C Programming · Unit 8 · 5 hrs
Structure and Union
Exam-focused notes for Structure and Union (C Programming, CSC115): what the TU syllabus asks and how it has actually been tested, with 8 solved past questions from this unit.
What this unit covers
- Introduction
- Array of structure
- Passing structure to function
- Passing array of structure to function
- Structure within structure (Nested Structure)
- Union
- Pointer to structure
Array of structure
Create a structure called STUDENT with data members SID, name, address, CGPA. Write a program to initialize the value of 100 students and display the information of those students whose address is "KTM" and CGPA is between 3.5 to 4. [5]
--- Part Description ------------------- struct STUDENT Defines the structure with members SID, name, address, CGPA struct STUDENT st[100] Declares an array of structures to hold 100 student records First for loop Reads and initializes data for all 100 stud...
Full solved answer →Differentiate between source code and object code.Create a structure named Book which remembers Book_Name, Price and Author. Then, make the list of top 10 records of book and print the name of authors having the price of book greater than 1000.[3+7]
(a) Difference Between Source Code and Object Code Basis Source Code Object Code --------------------------------- Definition The program written by a programmer in a high-level language (e.g., C) that is human-readable The machine-level code generated by t...
Full solved answer →Create a structure 'Employee' having Name, Address, Salary, and Age as member functions. Display the name of the employee having age between 40 and 50 and are living in Kathmandu. [5]
Concept Description ------ struct Employee Defines the structure with 4 members emp[100] Array of structure to store multiple employees strcmp() Compares Address string with "Kathmandu" (returns 0 if equal) Age = 40 && Age <= 50 Checks if age falls in the r...
Full solved answer →What is structure?How is it different from union?Create a structure named course with name, code and credit_hour as its member.Write a program using this structure to read data of 5 courses and display data of those courses with credit_hour greater than 3.[1+2+2+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. Syntax: --- Feature Structure Union --------- Keyword struct union ...
Full solved answer →Union
What is the advantage of the union over structure? List any four string library functions with the prototype. [5]
The primary advantage of union over structure is memory efficiency. In a structure, each member is allocated its own separate memory space, so the total memory used is the sum of all members' sizes. In a union, all members share the same memory location. Th...
Full solved answer →Structure within structure
Define structure.Explain nested structure with example.Create a structure named book with name, author, and publisher as its members.Write a program using this structure to read data of 50 books and display name of those books published by 'XXX' publisher.[1+2+2+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. Syntax: --- A nested structure is a structure that contains another...
Full solved answer →Introduction
What is structure? Create a structure rectangle with data members length and breath. [2+3]
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: - The definition starts with the keyword struct followed by a t...
Full solved answer →What is the structure? How is it different from array? Create a structure student having data members name, roll number and percentage.Complete the program to display the name of student having percentage greater than or equal to 60.[5+5]
--- (a) What is a Structure? 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 data member. Feature Array Structure --------- Da...
Full solved answer →Make Unit 8 stick
Practice CSC115 with flashcards & quizzes