In this program, we are going to share a C program to demonstrate the Nested Structure. If you are a beginner and want to start learning the C programming, then keep your close attention in this tutorial as I am going to share a C program to demonstrate the Nested Structure with the output.
We have designed this program for beginners for learning purpose. Copy below c program and execute it with c compiler to see the output of the program.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #include <stdio.h> //define the structure as student struct student{ char name[30]; int rollNo; struct dateOfBirth{ int dd; int mm; int yy; }DOB; }; int main() { struct student std; printf("Enter name: "); gets(std.name); printf("Enter roll number: "); scanf("%d",&std.rollNo); printf("Enter Date of Birth [DD MM YY] format: "); scanf("%d%d%d",&std.DOB.dd,&std.DOB.mm,&std.DOB.yy); printf("\nName : %s \nRollNo : %d \nDate of birth : %02d/%02d/%02d\n",std.name,std.rollNo,std.DOB.dd,std.DOB.mm,std.DOB.yy); return 0; } |
Enter name: John
Enter roll number: 073170290
Enter Date of Birth [DD MM YY] format: 14 07 89
Name : John
RollNo : 073170290
Date of birth : 14/07/89
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.