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 61–70 of 100
Topics in C Programming
What is the primary difference between passing a structure by value vs by pointer in function calls?
A Pointer passing creates a copy of the structure
B Value passing allows direct modification of original structure members
C Pointer passing is more memory efficient for large structures
D Value passing is faster for structures with more than 10 members
Correct Answer:  C. Pointer passing is more memory efficient for large structures
EXPLANATION

Passing by pointer avoids copying the entire structure, making it efficient for large data structures.

Take Test
Which of the following is true about typedef struct?
A typedef struct creates a named type, eliminating need for 'struct' keyword in declarations
B typedef struct is less efficient than regular struct
C typedef struct cannot be nested
D typedef struct allocates memory immediately
Correct Answer:  A. typedef struct creates a named type, eliminating need for 'struct' keyword in declarations
EXPLANATION

typedef creates an alias for the struct type, allowing direct use without 'struct' keyword.

Take Test
How much memory (in bytes) will the following structure occupy on a 32-bit system?
struct Data { char c; int i; short s; };
A 7
B 9
C 12
D 8
Correct Answer:  C. 12
EXPLANATION

Due to padding/alignment: char(1) + padding(3) + int(4) + short(2) = 12 bytes on 32-bit systems.

Take Test
What is the output of the following code?
struct Point { int x; int y; };
struct Point p = {5};
printf("%d %d", p.x, p.y);
A 5 0
B 5 garbage
C 0 5
D Compilation error
Correct Answer:  A. 5 0
EXPLANATION

When initializing a struct with fewer values than members, remaining members are zero-initialized. p.x=5, p.y=0.

Take Test
Which initialization method for structures is used in designated initializers (C99 feature)?
A struct s obj = {1, 2, 3};
B struct s obj = {.x = 1, .y = 2};
C struct s obj[]; obj[0].x = 1;
D struct s *obj = malloc(...);
Correct Answer:  B. struct s obj = {.x = 1, .y = 2};
EXPLANATION

Designated initializers (C99) allow specifying members by name using dot notation, making code more readable and maintainable.

Take Test
What is the relationship between structure alignment and padding in modern C compilers?
A They are unrelated concepts
B Padding is added to achieve proper alignment based on system architecture
C Alignment only applies to unions
D Padding reduces alignment efficiency
Correct Answer:  B. Padding is added to achieve proper alignment based on system architecture
EXPLANATION

Compilers add padding bytes between structure members to align them on boundaries (usually power of 2), improving memory access performance on the target architecture.

Take Test
In nested structures with pointers, which access method is correct? struct outer { struct inner *ptr; } *o; Accessing inner's member x:
A o->ptr->x
B (*o).ptr->x
C o->(*ptr).x
D Both A and B are correct
Correct Answer:  D. Both A and B are correct
EXPLANATION

Both o->ptr->x and (*o).ptr->x are equivalent. Arrow operator can chain for pointers, and (*pointer).member is equivalent to pointer->member.

Take Test
What will be the behavior of this code? struct s { int a; }; struct s obj = {5}; struct s *ptr = &obj; ptr->a = 10; printf("%d", obj.a);
A 5
B 10
C Garbage value
D Compilation error
Correct Answer:  B. 10
EXPLANATION

ptr points to obj, so ptr->a = 10 modifies obj.a to 10. The printf outputs the modified value 10.

Take Test
Which approach is more memory efficient for storing 100 flags: array of char or bit fields in a structure?
A Array of char (100 bytes)
B Bit fields (13 bytes approximately)
C Both use same memory
D Array is always better
Correct Answer:  B. Bit fields (13 bytes approximately)
EXPLANATION

Bit fields can pack 8 flags per byte, so 100 flags need ~13 bytes. Char array needs 100 bytes. Bit fields are more memory-efficient for flag storage.

Take Test
What is the difference between struct tag and struct type in C?
A Tag is the variable name, type is the structure name
B Tag is the structure name, type is the variable declaration
C They are the same thing
D Type is used in unions only
Correct Answer:  B. Tag is the structure name, type is the variable declaration
EXPLANATION

In 'struct person { int age; } p;', 'person' is the tag (structure name) and 'p' is the type/variable. Tag names the structure template; type creates actual instances.

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