C Programming · Unit 9
Structures and Unions
Exam-focused notes for Structures and Unions (C Programming, BIT102): what the TU syllabus asks and how it has actually been tested, with 8 solved past questions from this unit.
What this unit covers
- Structure definition and initialization
- Structure members and access
- Nested structures
- Union definition and initialization
- Differences between structure and union
- Typedef keyword
- Storing and displaying structure data
- Filtering structure records
Storing and displaying structure data
What is structure? Write a program to read roll, name and marks of 10 students using structure and then display all records. [1+4]
A structure is a user-defined data type in C that allows grouping of variables of different data types under a single name. Each variable inside a structure is called a member or field. Syntax: --- --- --- Feature Description ------ Keyword struct Members C...
Full solved answer →Write a program to store and display basic information (Roll, name, address, email. and phone) of students of using a structure. [5]
A structure in C is a user-defined data type that groups related variables of different data types under a single name. --- --- --- Feature Detail ------ struct Student User-defined structure with 5 members struct Student s[n] Array of structures to store m...
Full solved answer →Union definition and initialization
Write short notes on: a) Union b) Switch statement [0+2.5+2.5]
A union is a user-defined data type in C that allows storing different data types in the same memory location. All members of a union share the same memory space, and the size of the union is equal to the size of its largest member. Syntax: Example: Key Poi...
Full solved answer →Differences between structure and union
Differentiate between structure and union? Write a program to read employ id, name, post and salary of employee and display detail of those employee whose post is 'clerk'.[10]
--- Feature Structure Union --------- Keyword struct union Memory Allocation Each member gets its own separate memory All members share the same memory location Total Size Sum of sizes of all members Size of the largest member only Data Storage All members ...
Full solved answer →How structure is different from union? Write a program to store and display basic information (roll, name, address, email, and phone) of students of using a structure.[10]
Feature Structure Union --------- Keyword struct union Memory Allocation Each member gets its own separate memory All members share the same memory location Total Size Sum of sizes of all members Size of the largest member only Data Storage All members can ...
Full solved answer →What is union? Differentiate between pointer and array. [5]
--- A union is a user-defined data type in C that allows storing different data types in the same memory location. All members of a union share the same memory space, and the size of the union is equal to the size of its largest member. Syntax: Example: Her...
Full solved answer →Nested structures
How nested Structure is defined and initialized? Explain with an example.Write a program, using structure, to input records of 10 students. Members include name, roll number, marks obtained in math, C program and English. Display the records of students who have passed in C Program.[4+6]
(a) Nested Structure - Definition and Initialization A nested structure is a structure that contains another structure as one of its members. In other words, when a struct variable (or definition) is used as a member inside another struct, it is called a ne...
Full solved answer →Structure definition and initialization
Define structure. Write syntax for defining and initializing structure?Write a program that stores details of N employees (E_id, E_Name, Salary), and display the details of those employees whose salary is less than 10000.[5+5]
A structure is a user-defined data type in C that allows grouping of variables of different data types under a single name. Each variable inside a structure is called a member or field. Structures are used to represent a record, such as an employee, student...
Full solved answer →Make Unit 9 stick
Practice BIT102 with flashcards & quizzes