structures Flashcards
Question: What is the most commonly used data structure in C language programs aside from the array?
Answer: The struct or structure.
Question: What is a structure type in C language?
Answer: A structure type is a collection of not necessarily identical types used to define a group of variables as a single object.
Question: What is the difference between a primitive type and a derived type in C language?
Answer: A primitive type is a core language-defined type that cannot be redefined or introduced. On the other hand, a derived type is a collection of other types that can be declared using the struct keyword.
Question: What are the primitive types defined in C language?
Answer: The primitive types defined in C language are char, int, float, and double.
Question: How do you declare an object of int type called noSubjects?
Answer: To declare an object of int type called noSubjects, we write “int noSubjects;”.
Question: How do you declare a derived type in C language using the struct keyword?
Answer: The declaration of a derived type in C language using the struct keyword takes the form “struct Tag { //… declarations here };”, where Tag is the name by which we call the structure.
Question: What is an example of a structure type in C language?
Answer: An example of a structure type in C language is the Student struct, which consists of the student’s ID number and the student’s grades (up to 4 individual grades). Its declaration takes the form “struct Student { int idNum; float grade[4]; };” and does not allocate any memory for any object.
Question: What is a header file, and what is its purpose in multi-file source code?
Answer: A header file is a separate file that contains the declaration of a structure (or other code). Its purpose is to allow the code to be written in one spot and edited in that one spot alone. In multi-file source code, the header file’s code is inserted into the source file that requires that information.
Question: How do we allocate memory for an object of a structure?
Answer: To allocate memory for an object of a structure, we define it using the form “struct Tag identifier;”, where “Tag” is the name of the structure and “identifier” is the name of the object.
Question: What is the purpose of a structure type in C language programs?
Answer: The purpose of a structure type is to define a group of variables as a single object. A structure type is a collection of not necessarily identical types.
Question: What is a derived type in the C language?
Answer: In the C language, a derived type is a collection of other types. One example of a derived type is the struct or structure.
Question: What is the syntax for declaring a structure type in the C language?
Answer: The syntax for declaring a structure type in the C language is “struct Tag { [type] [identifier]; // … other types };”, where “Tag” is the name of the structure, “type” is the member’s type, and “identifier” is the name by which we access the member’s value.
Question: What is the purpose of a structure declaration?
Answer: The purpose of a structure declaration is to define the structure and the rules for objects of that type. It does not allocate any memory for any object.
Question: What is the purpose of a structure object?
Answer: The purpose of a structure object is to allocate memory for the structure so that it can be used in a program.
Question: What is the role of header files in modularity and organization of code?
Answer: Header files play an important role in modularity and organization of code. They often contain additional things like macros and function prototypes which help organize code.