Consider a structure with bit fields:
struct Flags {
unsigned int flag1 : 1;
unsigned int flag2 : 3;
unsigned int flag3 : 4;
};
What is the minimum size of this structure?
Answer: C
Bit fields must fit within an underlying integer type. Total bits = 8, which requires at least 4 bytes (one int on most systems).
Q.662Medium
What will happen if you try to compare two structures using the == operator directly?
Answer: B
C does not support direct comparison of structures using ==. You must compare members individually or use memcmp().
Q.663Easy
Given: struct Node { int data; struct Node *next; }; This represents which data structure concept?
Answer: B
A self-referential structure with a single pointer member is the fundamental building block of a singly linked list.
Q.664Easy
In the context of structures, what does 'self-referential' mean?
Answer: A
Self-referential structures contain pointers to their own type, enabling dynamic data structures like linked lists and trees.
Q.665Medium
Which of the following is a valid way to pass a structure to a function?
Answer: C
Structures can be passed by value (copying the entire structure) or by pointer (passing address) for efficiency.
Advertisement
Q.666Medium
In a nested structure scenario like struct A contains struct B, how do you access a member of B from A's variable?
Answer: C
If B is embedded in A: a_var.b_var.member. If B is a pointer in A: a_var->b_var->member or a_var.b_ptr->member.
Q.667Medium
What is the purpose of using anonymous structures/unions?
Answer: B
Anonymous structures allow direct member access without needing to reference the nested structure name.
Q.668Medium
Consider this structure: struct Complex { int real; int imag; }; If you want to create an array of 100 such structures, which declaration is correct?
Answer: A
Option A correctly creates a static array of 100 structures. Option B creates a pointer (and allocates incorrect size).
Q.669Hard
What is the output of this complex code?
struct S { char c; int i; } s;
printf("%lu", sizeof(s));
Answer: B
char(1 byte) + padding(3 bytes) + int(4 bytes) = 8 bytes due to alignment requirements.
Q.670Hard
In competitive programming, when you need a structure that can hold either an integer or a floating-point number (but not both simultaneously) in the most memory-efficient way, which should you use?
Answer: B
Union is memory-efficient as members share space. Only one can be accessed at a time, which suits the requirement.
Q.671Easy
What is the key difference between a structure and a union in C?
Answer: B
In structures, memory is allocated for each member independently. In unions, all members share the same memory location, so total memory allocated equals the size of the largest member.
Q.672Medium
Consider the following code:
struct Data {
int x;
char y;
double z;
};
Assuming int=4 bytes, char=1 byte, double=8 bytes, what is the size of struct Data due to padding?
Answer: D
Memory alignment causes padding. x(4) + padding(4) + y(1) + padding(7) + z(8) = 24 bytes. The compiler aligns to the largest member (double = 8 bytes).
Q.673Medium
Which feature in C allows you to define a structure without a tag name for use within another structure?
Answer: B
Anonymous structures allow defining structures without a tag name directly inside another structure, making members accessible as if they belong to the outer structure.
Q.674Hard
What will be the output of the following code?
union Test {
int a;
char b;
};
union Test t;
t.a = 65;
printf("%d %c", t.a, t.b);
Answer: D
Since union members share memory, the output depends on the system's endianness. On little-endian systems, t.b would be 65 (or 'A'), but on big-endian systems, the result differs.
Q.675Medium
In the context of bit fields in structures, what is the maximum number of bits that can be allocated to a single member in standard C?
Answer: C
The maximum number of bits for a bit field member cannot exceed the size of the underlying type. For int (typically 32 bits), you can allocate up to 32 bits to a single member.
Q.676Easy
struct Node { int data; struct Node *next; }; This is an example of which design pattern?
Answer: B
A self-referential structure contains a pointer to its own type. This is the fundamental building block for creating linked lists, trees, and other dynamic data structures.
Q.677Medium
Which of the following statements about structure initialization in C is INCORRECT?
Answer: B
Members do not need to be explicitly initialized. Uninitialized members in automatic structures have indeterminate values, while static structures have zero-initialized members. Designated initializers (C99+) allow flexible initialization order.
Q.678Easy
Given a structure with array members, how would you efficiently pass it to a function to avoid copying overhead?
Answer: B
Passing a pointer to the structure avoids copying the entire structure in memory, which is especially important for large structures with array members. This improves performance significantly.
Q.679Hard
In competitive programming for GATE/ISRO 2025, which scenario would union be preferable over structure?
Answer: B
Unions are preferred when you have mutually exclusive data (only one member is used at a time) and memory is critical. A classic example is storing different data types in a tagged union pattern used in compilers and interpreters.
Q.680Easy
Which function is used to open a file in C?
Answer: A
fopen() is the standard C library function used to open a file. It takes two arguments: filename and mode.