InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
Define structure. |
|
Answer» A structure is a collection of variables which can be of the same or different types. |
|
| 2. |
Define nested structures. |
|
Answer» When a structure is defined as a member of another structure the embedded structure is called a nested structure. |
|
| 3. |
What is a structure tag? |
|
Answer» Structure tag is a name given by the programmer and used to identify the structure during future re-definitions. |
|
| 4. |
What is the use of structures? |
|
Answer» Structures can be used to handle a group of logically related data items like register number, student name, subject marks, etc., under a single name. |
|
| 5. |
Explain the nesting of structures with an example. |
|
Answer» A structure defined as a member of another structure is called a nested structure. Example of a nested structure: struct date { int day; int month; int year; }; struct student { int regno; char name[20]; char class[10]; struct date dob; struct date admission date; }st1, st2, st3; In the above example, st1, st2, and st3 are the structure variable of type student and date is a structure definition. The members of student structure are regno, is an integer data type, name and class which are char type and dob admission date are date structure type variable members. The dob and admission date are and the structure variable who are members of another structure. |
|
| 6. |
What is an array of structures? |
|
Answer» Array of structure is a collection of array elements in which, each element of the array is a structure. |
|
| 7. |
What is a structure template? |
|
Answer» The list of all the structure members is called a template. |
|
| 8. |
What is the purpose of a struct keyword? |
|
Answer» It is the reserved or keyword, used in structure definition. |
|
| 9. |
Write the different methods of structure initialization. |
|
Answer» A struct variable can be initialized, like any other data variables in C++, at the time it is declared. We could use: struct student { char name[20]; int regno; float fees; } s1 = {“ram”, 25,24000.50}; or student s1 = {“ram”, 25,24000.50}; |
|
| 10. |
Give the difference between array and structure. |
|
Answer» An array is a collection of similar data elements under a single name whereas structure is a collection of dissimilar data elements under a single name. |
|
| 11. |
How is an array of structure declared? Give an example. |
|
Answer» The array of structure is a collection of array elements in which each element is a structure in the array. For example, struct student { int regno; char name [50]; char class [6]; } s[100]; |
|
| 12. |
Explain the elements of structure definition. Give an example. |
|
Answer» struct <structure-tag> { <data_type> <member variable1> <data_type> <member variable 2>list of members <data_type> < member variable 3> } <structure-variable-name1>,<sttructure-variable-name2>; 1.struct: It is the reserved or keyword used in structure definition. 2. <structure-tag>: It is the name given by the programmer and used to identity the structure in future re-definitions. They are used to declare structure variables. 3. <data_type>: Any valid data type in ‘C’. 4. < member variable 1…4>: are names of the variables. 5. <structure-variable-name 1,.2>: It is used to access the members of the structure. Example: struct student { int SP regno; char name[20]; char class[5]; char combination[4]; float fees; } st1, st2, st3; |
|
| 13. |
Give the declaration of structure. |
|
Answer» struct<structure-tag> { <data_type><member variable1> <data_type><member variable2> list of members <data_type><member variable3> } <structure-variable-name 1>,<structure-variable-name 2>; |
|
| 14. |
Write the structure definition to store name of the student, register number, class. |
|
Answer» struct student { int SP regno; char name[50]; char class[6]; }; |
|
| 15. |
How are structure members accessed? Give an example. |
|
Answer» The accessing of data of the members is done by using the following format: structure variable.member name for example cin>>s1.rollno>>s1.age>>s1.name>>s1.marks; |
|