Which of the following is a valid declaration of nested structure?
Answer: C
Both nested structure definitions (defining B inside A and declaring B as member) are valid in C.
Q.642Medium
What is the primary advantage of using unions in embedded systems?
Answer: A
Unions are primarily used in embedded systems to conserve memory by allowing multiple members to share the same memory location.
Q.643Hard
In a structure, what does the #pragma pack(1) directive do?
Answer: A
#pragma pack(1) removes padding, making members occupy consecutive memory locations for compact storage.
Q.644Easy
Which of the following correctly demonstrates a typedef for a structure?
Answer: A
The correct syntax for typedef struct is: typedef struct { members } StructName;
Q.645Hard
If a structure contains a flexible array member, where must it be declared?
Answer: B
A flexible array member must be the last member of a structure. This is a C99 feature used for dynamic-sized arrays.
Advertisement
Q.646Medium
How can you create a structure that can hold either an integer or a floating-point number, but not both simultaneously?
Answer: B
A union is the appropriate choice when you need to store different data types but only one value at a time.
Q.647Medium
What is the difference between 'struct' and 'typedef struct' in C?
Answer: B
typedef struct creates a type alias, allowing you to declare variables without using the 'struct' keyword each time.
Q.648Hard
In competitive programming, when implementing a graph using adjacency lists, which data structure is most suitable?
Answer: B
An array of structures, where each structure contains a linked list (using self-referential pointers), is ideal for adjacency list representation.
Q.649Medium
What will be the output if you read a union member that was not last written to?
Answer: A
Reading a union member that wasn't last written gives unpredictable results (garbage value or leftover bits from previous member).
Q.650Easy
Which of the following is the correct way to initialize a structure in C?
Answer: A
Structures must be initialized at declaration time using curly braces. Assignment of initializer list is not valid after declaration.
Q.651Hard
If you have a structure with bit fields, which statement about their behavior is true?
Answer: A
Bit fields save memory by storing multiple values in single bytes, but behavior varies by compiler/platform, and you cannot take addresses of bit field members.
Q.652Medium
In a nested structure scenario, how do you access a member of the inner structure?
Answer: C
Use dot operator (.) for direct structure variables and arrow operator (->) for pointers, or combinations for nested access.
Q.653Easy
Which of the following statements about structures is TRUE?
Answer: B
A structure allows grouping of different data types. Padding may be added by the compiler for alignment.
Q.654Medium
What is the size of the following structure on a 32-bit system?
struct Point {
char c;
int x;
double y;
}
Answer: D
char(1) + padding(3) + int(4) + double(8) = 16 bytes minimum, but alignment to double boundary makes it 24 bytes.
Q.655Easy
Consider the following code:
struct Data {
int a;
char b;
};
struct Data d = {10, 'A'};
Which method of initialization is used here?
Answer: B
Values are assigned in the order they appear in the structure definition, which is positional initialization.
Q.656Easy
What is the primary difference between a struct and a union in C?
Answer: A
In a union, all members occupy the same memory space, while struct members have individual memory locations.
Q.657Medium
What will be the output of this code?
union Data {
int a;
char b;
};
union Data d;
d.a = 257;
printf("%d %c", d.a, d.b);
Answer: C
Union shares memory. 257 in int format overwrites the char. On a little-endian system, only the lower byte (1) is stored in the char portion.
Q.658Easy
Which of the following correctly demonstrates accessing a member of a pointer to a structure?
Answer: B
Both (*ptr).member and ptr->member are valid. Option B uses explicit dereferencing, while the arrow operator is syntactic sugar for this.
Q.659Medium
What is the size of the following union?
union Test {
int a[5];
char b[10];
double c;
}
Answer: B
Union size equals the largest member. int[5] = 20 bytes, char[10] = 10 bytes, double = 8 bytes. Maximum is 20 bytes.
Q.660Easy
In C, what does the 'typedef' keyword do when used with structures?
Answer: A
typedef creates an alias, allowing you to use the structure name directly without using 'struct' keyword.