![]() |
A structure is a composite data type in C programming that enables combining several data types under one name. A structure inside a structure is also called a nested structure. In this article, we will learn how to declare a structure inside a structure in C++. Declare a Struct Inside a Struct in CTo declare a structure inside a structure, we need to first define the inner structure(the structure that we want to nest inside another structure) and then define the outer struct and include the inner struct as a member using the below syntax: Syntax to Declare Nested Structurestruct innerStructName { //define inner structure }; struct outerStructName { struct innerStructName st; // inner struct as Direct member }; We can also declare it directly inside the parent structure: struct outerStructName { struct innerStructName { //define inner structure }; }; C Program to Declare Struct Inside a StructThe below program demonstrates how we can declare a nested structure and use it in C. C
Output
Outer Data: 0 Inner Char: X Inner Float: 5.14 |
Reffered: https://www.geeksforgeeks.org
C Language |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |