Accessing members of Nested Structure in C language – Example of Structure with in Structure.
This code snippet will access the members of Nested Structure in C programming language, this program will demonstrate working with structure within structure i.e. Nested Structure.
C Code Snippet - Access members of Nested Structure
/*Accessing member from nested structure (structure with in structure).*/
#include <stdio.h>
//structure declaration
struct Outer{
int oVar;
struct Inner{
int iVar;
}IN;
}OUT;
/*Here Outer is outer structure and Inner is inner structure*/
int main()
{
//assigning value to oVar and iVar
OUT.oVar=10;
OUT.IN.iVar =20;
//printing values
printf("oVar: %d, iVar: %d\n",OUT.oVar, OUT.IN.iVar);
return 0;
}
oVar: 10, iVar: 20