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

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
/*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!

Load comments ↻


Advertisement
Advertisement
Advertisement



Copyright © 2024 www.includehelp.com. All rights reserved.