Friday, October 29, 2010

structure inside the another structure

/*
 * Structure inside the another structure.c
 *
 *  Created on: Oct 19, 2010
 *      Author: Karthikeyan.D
 */

# include <malloc.h>
struct employee
{
    int nage;
    int nsex;

};

struct NetSim
{
    int nTest;
    struct employee *pstruEmp;
};

struct NetSim *pstruNetsimDepartment =NULL;


# include <stdio.h>
int main()
{
  //To create  a memory for first structure
    pstruNetsimDepartment = (struct NetSim * )malloc (sizeof(struct NetSim *));

  //To create  a memory for second structure
    pstruNetsimDepartment->pstruEmp = (struct employee * )malloc (sizeof(struct employee *));

    // To assign the employee age as ten

    pstruNetsimDepartment->pstruEmp->nage =10;
// echo this meesge
    printf("%d",pstruNetsimDepartment->pstruEmp->nage);
    return 0;
}

No comments:

Post a Comment