Tuesday, April 4, 2017

Structure with example of typedef

#include<stdio.h>

 struct anything ///44 B
{
    int age;    ///4 B
    char name[20]; ///20 B           ///member definition
    char dept[10];///20 B

};

 typedef struct anything newType ;

  newType student1,student2 ;

main()
{
    printf("         Info of student 1 : \n");

    printf("Name = ");
    gets(student1.name);
    printf("Age = ");
    scanf("%d",&student1.age);
    printf("Dept = ");
    getchar();
    gets(student1.dept);




    printf("Name = ");
    puts(student1.name);
    printf("Age  = %d\n",student1.age);
    printf("Dept = ");
    puts(student1.dept);





    printf("         Info of student 2 : \n");

    printf("Name = ");
    gets(student2.name);
    printf("Age = ");
    scanf("%d",&student2.age);
    printf("Dept = ");
    getchar();
    gets(student2.dept);




    printf("Name = ");
    puts(student2.name);
    printf("Age  = %d\n",student2.age);
    printf("Dept = ");
    puts(student2.dept);

}

No comments:

Post a Comment