Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

490 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 161–170 of 490
Topics in C Programming
Q.161 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.

Test
Q.162 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().

Test
Q.163 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).

Test
Q.164 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.

Test
Q.165 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.

Test
Q.166 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.

Test
Q.167 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.

Test
Q.168 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).

Test
Q.169 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.

Test
Q.170 Medium Structures & Unions
How can you create a structure that can hold either an integer or a floating-point number, but not both simultaneously?
A Using a structure with conditional compilation
B Using a union instead of a structure
C Using an array of mixed types
D Using a pointer to void
Correct Answer:  B. Using a union instead of a structure
EXPLANATION

A union is the appropriate choice when you need to store different data types but only one value at a time.

Test
IGET
IGET AI
Online · Exam prep assistant
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