ADVERTISEMENT
ADVERTISEMENT

Accessing members of Nested Structure in C language – Example of Structure with in Structure.


IncludeHelp 15 June 2016

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

ADVERTISEMENT




ADVERTISEMENT



Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.