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 161–170 of 499
Topics in C Programming
Q.161 Medium Structures & Unions
In a nested structure scenario like struct A contains struct B, how do you access a member of B from A's variable?
A a_var->b_member
B a_var.b_var.c_member
C Both A and B are correct depending on context
D a_var..c_member
Correct Answer:  C. Both A and B are correct depending on context
EXPLANATION

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.

Take Test
Q.162 Medium Structures & Unions
Which of the following is a valid way to pass a structure to a function?
A Pass by value only
B Pass by pointer only
C Both pass by value and pass by pointer
D Pass by reference only
Correct Answer:  C. Both pass by value and pass by pointer
EXPLANATION

Structures can be passed by value (copying the entire structure) or by pointer (passing address) for efficiency.

Take Test
Q.163 Medium Structures & Unions
What will happen if you try to compare two structures using the == operator directly?
A It compares all members automatically
B It results in a compilation error
C It returns the comparison of the first members only
D It compares the memory addresses of the structures
Correct Answer:  B. It results in a compilation error
EXPLANATION

C does not support direct comparison of structures using ==. You must compare members individually or use memcmp().

Take Test
Q.164 Medium Structures & Unions
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?
A 1 byte
B 2 bytes
C 4 bytes
D 8 bytes
Correct Answer:  C. 4 bytes
EXPLANATION

Bit fields must fit within an underlying integer type. Total bits = 8, which requires at least 4 bytes (one int on most systems).

Take Test
Q.165 Medium Structures & Unions
What is the size of the following union?
union Test {
int a[5];
char b[10];
double c;
}
A 10 bytes
B 20 bytes
C 30 bytes
D 24 bytes
Correct Answer:  B. 20 bytes
EXPLANATION

Union size equals the largest member. int[5] = 20 bytes, char[10] = 10 bytes, double = 8 bytes. Maximum is 20 bytes.

Take Test
Q.166 Medium Structures & Unions
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);
A 257 A
B 257 \0
C 1 A
D 257 1
Correct Answer:  C. 1 A
EXPLANATION

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.

Take Test
Q.167 Medium Structures & Unions
What is the size of the following structure on a 32-bit system?
struct Point {
char c;
int x;
double y;
}
A 13 bytes
B 16 bytes
C 20 bytes
D 24 bytes
Correct Answer:  D. 24 bytes
EXPLANATION

char(1) + padding(3) + int(4) + double(8) = 16 bytes minimum, but alignment to double boundary makes it 24 bytes.

Take Test
Q.168 Medium Structures & Unions
In a nested structure scenario, how do you access a member of the inner structure?
A outer.inner.member
B outer->inner->member
C Both A and B (depending on whether it's direct or pointer)
D outer[inner][member]
Correct Answer:  C. Both A and B (depending on whether it's direct or pointer)
EXPLANATION

Use dot operator (.) for direct structure variables and arrow operator (->) for pointers, or combinations for nested access.

Take Test
Q.169 Medium Structures & Unions
What will be the output if you read a union member that was not last written to?
A Garbage value or previous data
B Zero by default
C Compiler warning only
D Runtime error
Correct Answer:  A. Garbage value or previous data
EXPLANATION

Reading a union member that wasn't last written gives unpredictable results (garbage value or leftover bits from previous member).

Take Test
Q.170 Medium Structures & Unions
What is the difference between 'struct' and 'typedef struct' in C?
A No difference, both are identical
B typedef struct creates an alias, avoiding the need to write 'struct' keyword repeatedly
C struct is faster than typedef struct
D typedef struct only works with unions
Correct Answer:  B. typedef struct creates an alias, avoiding the need to write 'struct' keyword repeatedly
EXPLANATION

typedef struct creates a type alias, allowing you to declare variables without using the 'struct' keyword each time.

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