What are the uses of structure? Explain with an example. Also explain concept of nested Structures. (2024)

A structure is a collection of variables of same or different datatypes.It is useful in storing or using informations or databases.

Example: An employee’s record must show its salary, position, experience, etc. It all can be stored in one single variable using structures.

struct Employee {char ename[20];int id;float salary,experience; };

Structure written inside another structure is called as nesting of two structures. Nested Structures are allowed in C Programming Language. We can write one Structure inside another structure as member of another structure.

Example:

struct date{int date;int month;int year; };struct Employee {char ename[20];int ssn;float salary;struct date doj;};

Here, struct date is passed as a member of struct employee. Hence, nested.

ADD COMMENTEDIT

What are the uses of structure? Explain with an example. Also explain concept of nested Structures. (2024)

FAQs

What is nested structure with an example? ›

C provides us the feature of nesting one structure within another structure by using which, complex data types are created. For example, we may need to store the address of an entity employee in a structure.

What is a structure and its use? ›

A structure is an arrangement and organization of interrelated elements in a material object or system, or the object or system so organized. Material structures include man-made objects such as buildings and machines and natural objects such as biological organisms, minerals and chemicals.

Which of the following is an example of a nested structure? ›

The correct option is D. If else inside a for loop.An example of a nested structure is a structure that is defined inside another structure. The structures are usually loops or conditional statements such as if-then-else statements.

What is structure in C with an example? ›

A structure is a data type that can contain unlimited numbers of NAMED sub categories (or fields). For example, a student record may contain the students, name, age, gpa, etc. Each category of information is defined by its name and type (e.g., name is a string, age is an integer).

What is the use of nested? ›

As mentioned in the section Nested Classes, nested classes enable you to logically group classes that are only used in one place, increase the use of encapsulation, and create more readable and maintainable code.

What is the use of nested selection structure? ›

A nested selection structure is one in which either the true path or the false path includes yet another selection structure. Any of the statements within either the true or false path of one selection structure may be another selection structure.

What is the importance of using structure? ›

Good structure performs these functions: It provides the framing for our work, why it is important, and the context of it. It defines what work we will do. It defines how we interrelate with others.

What are the 4 types of structures? ›

Frame structures: Made of beams and columns, like in buildings. Shell structures: Curved or dome-shaped, like some roofs or eggshells. Truss structures: Made of interconnected triangles, often used in bridges. Arch structures: Curved, like bridges or doorways.

Why do people use structure? ›

If your days are generally structure-less it is much easier to forget to eat, take breaks or miss important regular tasks [4]. A regular structure also creates a sense of familiarity and control that can reduce your stress levels and help you feel more in control of your time and life generally.

What is nested function with example? ›

A nested function is a function that is completely contained within a parent function. Any function in a program file can include a nested function. The primary difference between nested functions and other types of functions is that they can access and modify variables that are defined in their parent functions.

Can a structure be nested? ›

Yes it is possbile to Nest a structure.

What are nested data structures? ›

In more detail, a nested data structure is essentially a structure that contains one or more other structures of the same or different type. This is a powerful concept in computer science as it allows for the creation of complex data models that can represent real-world situations more accurately.

What is structure and example? ›

A structure is something of many parts that is put together. A structure can be a skyscraper, an outhouse, your body, or a sentence. Structure is from the Latin word structura which means "a fitting together, building." Although it's certainly used to describe buildings, it can do more than that.

What is an example of a structure within a structure in C? ›

struct school{ int numberOfStudents; int numberOfTeachers; struct student{ char name[50]; int class; int roll_Number; } std; }; Explanation: In the above example of nested structure in C, there are two structures Student (depended structure) and another structure called School(Outer structure).

What is structure C and what is its purpose? ›

A struct in the C programming language (and many derivatives) is a composite data type (or record) declaration that defines a physically grouped list of variables under one name in a block of memory, allowing the different variables to be accessed via a single pointer or by the struct declared name which returns the ...

What is an example of a nested variable? ›

Nesting, like crosstabulation, can show the relationship between two categorical variables, except that one variable is nested within the other in the same dimension. For example, you could nest Gender within Age category in the row dimension, showing the number of males and females in each age category.

What is the nested loop explain by using an example? ›

If a loop exists inside the body of another loop, it's called a nested loop. Here's an example of the nested for loop. // outer loop for (int i = 1; i <= 5; ++i) { // codes // inner loop for(int j = 1; j <=2; ++j) { // codes } .. } Here, we are using a for loop inside another for loop.

What is nested data structure? ›

A nested data structure is a data structure within another data structure, allowing for more complex data organisation. In more detail, a nested data structure is essentially a structure that contains one or more other structures of the same or different type.

Top Articles
Latest Posts
Article information

Author: Tuan Roob DDS

Last Updated:

Views: 5346

Rating: 4.1 / 5 (42 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Tuan Roob DDS

Birthday: 1999-11-20

Address: Suite 592 642 Pfannerstill Island, South Keila, LA 74970-3076

Phone: +9617721773649

Job: Marketing Producer

Hobby: Skydiving, Flag Football, Knitting, Running, Lego building, Hunting, Juggling

Introduction: My name is Tuan Roob DDS, I am a friendly, good, energetic, faithful, fantastic, gentle, enchanting person who loves writing and wants to share my knowledge and understanding with you.