Please enable JavaScript.
Coggle requires JavaScript to display documents.
INTRODUCTION TO STRUCTURES - Coggle Diagram
INTRODUCTION TO STRUCTURES
STRUCTURES
Q1. How do structures help represent real-world objects?
Ans. Structures group related information of different data types under one name, making it easier to represent real-world objects like students and employees.
Q2. Can a structure have members of different data types?
Ans. Yes, a structure can contain members of different data types, such as integers, characters, floating-point numbers, and arrays.
Q3. Name three members of a Student structure.
Ans. Three members of a Student structure can be roll number (int), name (char array), and marks (float).
STRUCTURE VARIABLES
Q4. Does defining a structure allocate memory?
Ans. No, defining a structure only creates a blueprint. Memory is allocated when variables of that structure type are declared.
Q5. How can members be given values one by one?
Ans. Structure members can be assigned values individually using the dot (.) operator with the structure variable name.
Q6. Can we create more than one variable from the same structure?
Ans. Yes, multiple variables can be created from the same structure type, and each variable stores its own separate data.
STRUCTURES VS ARRAYS
Q7. How are array elements accessed, and how are structure members accessed?
Ans. Array elements are accessed using index numbers with square brackets, whereas structure members are accessed using the dot (.) operator.
Q8. Give one example of data suited to an array and one suited to a structure.
Ans. An array is suitable for storing student marks, while a structure is suitable for storing student details like name, roll number, and marks.
Q9. Can two structures be compared directly using ==?
Ans. No, two structure variables cannot be compared directly using == in C. Their individual members must be compared separately.
NESTED STRUCTURES AND ARRAYS OF STRUCTURES
Q10. How do you access a member of an inner structure?
Ans. An inner structure member is accessed using multiple dot operators, such as student.address.city, to reach the required member.
Q11. What does one element of an array of structures represent?
Ans. Each element of an array of structures represents one complete record, containing all the details of a particular object.
Q12. How are loops useful with an array of structures?
Ans. Loops help access, input, display, and process multiple structure records efficiently without writing separate statements for every element.
STRUCTURES & FUNCTIONS
Q13. Why is passing a structure better than passing each member separately?
Ans. Passing a structure is convenient because all related data members are transferred together, reducing function arguments and making the program easier to manage.
Q14. In pass by reference, what is passed to the function: a copy or an address?
Ans. In pass by reference, the address of the original structure variable is passed, allowing the function to access and modify its members.
Q15. Which is more memory-efficient for large structures, pass by value or pass by reference?
Ans. Pass by reference is more memory-efficient because it passes only the structure's address instead of creating a complete copy of its data.