Nested structure in C programming language

Nested structure in C programming language

In this tutorial, we will discuss the concept of Nested structure in C programming language.

Nested structure is allowed in C programming language.  Nested structure means structure within the another structure. It means we can declare one structure inside another structure.

We can create nesting structure in two way:

1. Declaring a structure variable as Member of another structure – by separated

Syntex

struct strucuture_Name         
                   {                                        
               <variable_type1> <variable_name>;       
                <variable_type2> <variable_name>;          
                        };                                 
                    
 struct strucuture_Name                          
          {                                                 
       <variable_type1> <variable_name>;                     
       <variable_type2> <variable_name>;                     
          };                            


Example

struct house_address
{
char born_city[30];
int postal_code;
};//one structure
struc student
{

int  stu_id;

char stu_name;
};//another structure

Syntex



2. Declaring a structure inside another structure – by Embedded or inner

struct Employee
{
int emp_id;
char emp_name;
struct dob
{
int dd;
int mm;
int yyyy;
}

}
Syntex
Program 1
Example

When the above code is executed it produces the following result

employee id :14
employee name :jegan sing
employee dob :19/4/2017

Program 2

Example

When the above code is executed it produces the following result

22
33
44
55

 

Structure in C Language                                       Structure in C++ Language
Function in C Language                                            structure  within structure in C++   

 

Karmehavannan

Recent Posts

Multiply two numbers in Java using scanner| 5 different ways

Multiply two numbers in Java using scanner| 5 different ways In this article, we will…

9 months ago

5 different ways to Divide two numbers in Java using scanner

5 Different ways to Divide two numbers in Java using scanner In this article, we…

10 months ago

Learn 8 Ways to Subtract Two Numbers Using Methods in Java

Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…

10 months ago

10 ways to subtract two numbers in Java

10 ways to subtract two numbers in Java In this article, we will discuss the…

10 months ago

Java Code Examples – Multiply Two Numbers in 5 Easy Ways

Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…

10 months ago

How to Divide two numbers in Java| 5 different ways

How to Divide two numbers in Java| 5 different ways In this article, we will…

10 months ago

This website uses cookies.