Ques 1 Structure
What is the output of the following C Code?
#include<stdio.h> struct Student { int roolNo; //int size=4 byte char gender; //char size=1 byte char name[10]; }; int main() { struct Student s1; printf("%d", sizeof(s1)); return 0; }
The size of the struct Student is the sum of the sizes of its members, which are:
int roolNo = 4 bytes
char gender = 1 byte
char name[10] = 10 bytes
So, the total size of the struct Student would be 4 + 1 + 10 = 15 bytes.
However, in most systems, the memory is allocated in multiples of the machine word size, which is usually 4 bytes. Therefore, the actual size of the struct Student would be rounded up to the nearest multiple of 4, which is 16 bytes.
Therefore, the output of printf("%d", sizeof(s1)) would be 16.
Ques 2 Structure
What will happen if a structure member is accessed before it is initialized?
Undefined behavior
Ques 3 Structure
What is the correct syntax to declare an array of structures in C?
struct person arr[5];
Ques 4 Structure
Can a structure be used as a member of another structure in C?
Yes, it’s completely allowed
Ques 5 Structure
Which of the following code will result in a compiler error?
struct student { struct student next; };
Ques 6 Structure
What is the purpose of the typedef keyword when used with structures in C?
It allows defining a new name for the structure type