C MCQ
C MCQ
a) 0 1 2 3
b) 1 2 3 4
c) 0 1 2 3 4
d) Compile-time error
Answer: a) 0 1 2 3
a) 0 1 2 3 4
b) Infinite loop printing 0
c) Compile-time error
d) Undefined behavior
Answer: b) Infinite loop printing 0
3. Nested Loops
for (int i = 1; i <= 2; i++) {
for (int j = 1; j <= 3; j++) {
printf("%d ", i * j);
}
}
a) 1 2 3 2 4 6
b) 1 2 2 3 3 4
c) 1 2 3 1 2 3
d) Compile-time error
Answer: a) 1 2 3 2 4 6
4. do-while Loop
int i = 5;
do {
printf("%d ", i);
i--;
} while (i > 0);
a) 5 4 3 2 1
b) 4 3 2 1
c) 5 4 3 2 1 0
d) Compile-time error
Answer: a) 5 4 3 2 1
printf("%d", arr[3]);
a) 1
b) 2
c) 0
d) Garbage value
Answer: c) 0
a) 7
b) 12
c) 0
d) Compile-time error
Answer: b) 12
a) Hello
b) Compile-time error
c) Nothing
d) Undefined behavior
Answer: a) Hello
3. Passing Arrays to Functions
void printArray(int arr[], int size) {
for (int i = 0; i < size; i++) {
printf("%d ", arr[i]);
}
}
int main() {
int arr[] = {1, 2, 3};
printArray(arr, 3);
}
a) 1 2
b) 1 2 3
c) Compile-time error
d) Garbage value
Answer: b) 1 2 3
a) 11
b) Compile-time error
c) Undefined behavior
d) None of the above
Answer: b) Compile-time error
5. Recursion
int factorial(int n) {
if (n == 0)
return 1;
return n * factorial(n - 1);
}
int main() {
printf("%d", factorial(4));
}
a) 12
b) 24
c) 16
d) Compile-time error
Answer: b) 24
1. Function Declaration
3. Passing Arguments
1. Data Types
2. Storage Classes
3. Preprocessor Directives
5. Pointers
1. Declaration of enum
a) 0
b) 1
c) Undefined
d) Depends on the compiler
Answer: a) 0
3. Purpose of typedef
4. Example of typedef
a) 0
b) 2
c) 3
d) Undefined
Answer: c) 3
1. Definition of Union
What is a union in C?
a) A data type that stores multiple variables of different types simultaneously
b) A data type that stores multiple variables of different types but uses the same memory
location
c) A data type similar to an array
d) A data type that allows dynamic memory allocation
Answer: b) A data type that stores multiple variables of different types but uses the same
memory location
2. Size of a Union
The size of a union in C is:
a) The sum of the sizes of its members
b) The size of its largest member
c) Always 4 bytes
d) None of the above
Answer: b) The size of its largest member
union data {
int i;
float f;
};
union data d;
d.i = 10;
printf("%f", d.f);