Home Subjects C Programming Structures & Unions

C Programming
Structures & Unions

C language from basics to advanced placement prep

100 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 81–90 of 100
Topics in C Programming
In C, what is a self-referential structure?
A A structure that contains a member pointing to itself
B A structure that calls its own constructor
C A structure with recursive function definitions
D A structure that inherits from itself
Correct Answer:  A. A structure that contains a member pointing to itself
EXPLANATION

A self-referential structure contains a pointer to its own type, commonly used in creating linked lists, trees, and other data structures.

Take Test
What will be the output of sizeof() for the following union? union data { int a; float b; double c; }
A 4 bytes
B 8 bytes
C 12 bytes
D 16 bytes
Correct Answer:  B. 8 bytes
EXPLANATION

The size of a union is the size of its largest member. Here, double (8 bytes) is the largest, so sizeof(union data) = 8 bytes.

Take Test
Which of the following is a key difference between struct and union in C?
A Struct members share memory while union members don't
B Union members share memory while struct members don't
C Both allocate same memory to all members
D Union cannot have more than 2 members
Correct Answer:  B. Union members share memory while struct members don't
EXPLANATION

In unions, all members share the same memory location, so only one member can hold a value at a time. In structs, each member has its own memory space.

Take Test
Given union test { int x; char y[4]; }; If you set y[0]=65, y[1]=66, what happens to x?
A x remains 0
B x becomes unpredictable
C x gets modified based on byte representation
D x automatically converts to string
Correct Answer:  C. x gets modified based on byte representation
EXPLANATION

Since union members share memory, setting y[0]=65 and y[1]=66 overwrites the int x value. The exact value depends on endianness.

Take Test
What is the difference between self-referential and recursive structures?
A They are the same thing
B Self-referential contains pointer to same type, recursive is function-based
C Recursive structures are not allowed in C
D Self-referential requires extern keyword
Correct Answer:  B. Self-referential contains pointer to same type, recursive is function-based
EXPLANATION

Self-referential structures contain pointers to the same structure type (like linked list nodes). Recursion refers to function calls, not structures.

Take Test
How can you initialize a structure array of 10 elements partially in C?
A struct emp arr[10] = {0};
B struct emp arr[10] = {};
C struct emp arr[10] = {NULL};
D Both A and B are correct
Correct Answer:  D. Both A and B are correct
EXPLANATION

Both {0} and {} will initialize all members to zero. These are equivalent in C99 and later standards.

Take Test
What happens if you assign a union member and then access another member?
struct u { int a; char b; }; u.a = 257; printf("%d", u.b);
A Prints 257
B Prints 1 (LSB of 257)
C Prints garbage
D Compilation error
Correct Answer:  B. Prints 1 (LSB of 257)
EXPLANATION

In a union, both members share memory. 257 in binary is 100000001. u.b (char) reads only the LSB, which is 1.

Take Test
Which statement is true about nested structures in C?
A Nested structures are not allowed
B A structure can contain another structure as a member
C Nested structures require pointers
D Nested structures can only be used with unions
Correct Answer:  B. A structure can contain another structure as a member
EXPLANATION

C allows structures to have other structures as members. This is called nested structures and is a common practice.

Take Test
Consider: union u { int x; double y; }; What is sizeof(u)?
A 4 bytes
B 8 bytes
C 12 bytes
D 16 bytes
Correct Answer:  B. 8 bytes
EXPLANATION

The size of a union is equal to its largest member. double is typically 8 bytes, which is larger than int (4 bytes).

Take Test
What is the purpose of padding in structures?
A To waste memory intentionally
B To align data for faster CPU access
C To prevent hacking
D To increase security
Correct Answer:  B. To align data for faster CPU access
EXPLANATION

Padding ensures that structure members are aligned in memory according to their natural boundaries, improving CPU access speed.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips