What do you mean by nested structure




















So Nested structures as its name suggest in C is kind of defining one structure inside another structure. Any member variables can be defined inside a structure and in turn, that structure can further be moved into another structure. The variables inside a structure can be anything like normal or pointer or anything and can be placed anywhere within the structure.

From the above syntax, we can infer the fact that mem1 structure nested inside member1 structure will contain the member or the variable to be accessed and everyone can be accessed in a nested manner by using. We will take more examples to get clarity on how the syntax satisfies the working of the nested structure. In the above example, man structure is defined inside an employee structure which is a nested structure.

Members within the nested structure which is a man can be accessed using the below syntax or format. So, it's mandatory for you to first define person structure before using it's variable as a member of the structure student.

The advantage of using this method is that now we can declare a variable of type struct person in anywhere else in the program. In lines , we have declared another structure called student whose one of the members is of type struct student declare above.

The next five scanf statements lines asks the user to enter the details of the students which are then printed using the printf lines statement. Load Comments. Hence, to store the address of the employee, we need to store the address of the employee into a separate structure and nest the structure address into the structure employee. Consider the following program. Here, we create two structures, but the dependent structure should be used inside the main structure as a member.

Consider the following example. As you can see, doj date of joining is the variable of type Date. Here doj is used as a member in Employee structure. In this way, we can use Date structure in many structures. The embedded structure enables us to declare the structure inside the structure. Hence, it requires less line of codes but it can not be used in multiple data structures. Just like other variables, a structure can also be passed to a function.

We may pass the structure members into the function or pass the structure variable at once. Consider the following example to pass the structure variable employee to a function display which is used to display the details of an employee. JavaTpoint offers too many high quality services. Explain structures in C? What do you mean by nested structure? A company needs to maintain data about their employees.

Details to be maintained are Employee name,Department,Date of joining,salary. Please log in to add an answer. Continue reading The best way to discover useful content is by searching it.



0コメント

  • 1000 / 1000