Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

499 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 181–190 of 499
Topics in C Programming
Q.181 Medium Structures & Unions
What is the issue with bit fields in structures regarding portability?
A Bit field ordering is implementation-dependent
B Bit fields cannot be used with pointers
C Bit fields always consume 32 bits regardless of size
D Bit fields cannot be initialized
Correct Answer:  A. Bit field ordering is implementation-dependent
EXPLANATION

Bit field allocation order (left-to-right or right-to-left) varies across compilers, affecting portability.

Take Test
Q.182 Medium Structures & Unions
What will be the output of this code?
union Data { int x; char y; };
Data d = {65};
d.y = 'A';
printf("%d", d.x);
A 65
B 97
C 65 then 97
D Undefined behavior
Correct Answer:  D. Undefined behavior
EXPLANATION

Modifying y changes the same memory location as x. Only the last byte of x is affected, leading to unpredictable output.

Take Test
Q.183 Medium Structures & Unions
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
Q.184 Medium Structures & Unions
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
Q.185 Medium Structures & Unions
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
Q.186 Medium Structures & Unions
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
Q.187 Medium Structures & Unions
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
Q.188 Medium Structures & Unions
Which statement is correct about bit fields in structures?
A They can be applied to any data type
B They are used to pack multiple members into fewer bytes
C They increase the structure size
D They make structures faster to access
Correct Answer:  B. They are used to pack multiple members into fewer bytes
EXPLANATION

Bit fields allow you to specify the number of bits for integral members, enabling memory optimization by packing multiple small values into a single byte.

Take Test
Q.189 Medium Structures & Unions
What happens when you modify a union member that overlaps with another?
A Both members update independently
B The previous member value is preserved
C The previous member's value gets overwritten
D A compilation error occurs
Correct Answer:  C. The previous member's value gets overwritten
EXPLANATION

Since union members share memory, modifying one member overwrites the value of other members because they occupy the same memory location.

Take Test
Q.190 Medium Structures & Unions
Which of the following correctly initializes a structure array? struct point { int x, y; } arr[3] = ?
A { {1,2}, {3,4}, {5,6} }
B { 1,2,3,4,5,6 }
C [ {1,2}, {3,4}, {5,6} ]
D None of the above
Correct Answer:  A. { {1,2}, {3,4}, {5,6} }
EXPLANATION

Structure arrays are initialized with nested braces, where each set of braces contains initialization values for one structure element.

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