Structure in C MCQs Exercise II

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;
}

A 4
B 1
C 10
D 16

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?

A Compiler error
B Undefined behavior
C It will have a value of 0
D It will have a random value

Undefined behavior

Ques 3 Structure


What is the correct syntax to declare an array of structures in C?

A struct person arr[5];
B struct arr[5] person;
C person arr[5];
D struct arr[5] {person};

struct person arr[5];

Ques 4 Structure


Can a structure be used as a member of another structure in C?

A No, it’s not allowed
B Yes, but only with certain restrictions
C Yes, it’s completely allowed
D Only if the structure is a pointer

Yes, it’s completely allowed

Ques 5 Structure


Which of the following code will result in a compiler error?

A struct student { char name[50]; int rollNo; };
B struct student { struct student *next; };
C struct student { struct teacher *next; };
D struct student { struct student next; };

struct student { struct student next; };

Ques 6 Structure


What is the purpose of the typedef keyword when used with structures in C?

A It creates a new instance of the structure
B It allows defining a new name for the structure type
C It ensures memory optimization for the structure
D It automatically initializes the structure members

It allows defining a new name for the structure type