C Programming Multiple Choice Question MCQ
Categories: MCQS
Q1. Pseudocode: FUNCTION Add(a, b) RETURN a PLUS b END FUNCTION CALL Add(5, 10) (A) 15 (B) 5 (C) 10 (D) Error Answer: 15 Q2. Pseudocode: FUNCTION CheckEven(number) IF number MOD 2 EQUALS 0 THEN RETURN True ELSE RETURN False END FUNCTION CALL CheckEven(4) (A) True (B) False (C) Error (D) None Answer: True Q3. Pseudocode: FUNCTION Fibonacci(n) IF n LESS THAN OR EQUAL TO 1 THEN RETURN n ELSE RETURN Fibonacci(n-1) PLUS Fibonacci(n-2) END FUNCTION CALL Fibonacci(5) (A) 5 (B) 8 (C) Error (D) None Answer: 5 Q4. Identify the error in this C code: int main() { printHello(); return 0; } void printHello() { printf("Hello"); } (A) Missing declaration of printHello (B) Syntax error (C) No error (D) Wrong function call Answer: Missing declaration of printHello Q5. Spot the mistake: int main() { int result = sum(5, 10); printf("%d", result); return 0; } int sum(int a, int b) { return; } (A) Missing return value in sum (B) Syntax error (C) No error (D) Incorrect function parameters Answer: Missing return value in sum Q6. Find the error: int main() { int x = 5; increment(&x); printf("%d", x); return 0; } void increment(int* n) { *n++; } (A) Incorrect pointer usage in increment (B) Syntax error (C) No error (D) Wrong printf format Answer: Incorrect pointer usage in increment Q7. How do you declare an array of integers in C? (A) int arr[10]; (B) array int[10]; (C) int array 10; (D) [10]int array; Answer: int arr[10]; Q8. Which index is used to access the first element of an array in C? (A) 0 (B) 1 (C) -1 (D) First Answer: 0 Q9. What happens when you try to access an array element outside its bounds in C? (A) Syntax error (B) Compilation error (C) Runtime error (D) Undefined behavior Answer: Undefined behavior Q10. How do you initialize an array in C? (A) With any value (B) With 0s (C) With 1s (D) Cannot be initialized Answer: With any value Q11. Which of the following is a correct way to pass an array to a function in C? (A) By specifying the size of the array (B) By passing the first element (C) By passing the array name (D) By passing each element individually Answer: By passing the array name Q12. What is the size of a 2-dimensional array int arr[3][4]; in C? (A) 3 (B) 4 (C) 12 (D) Cannot be determined Answer: 12 Q13. How can you access the third element in the second row of a 2D array int arr[3][4]; in C? (A) arr[1][2] (B) arr[2][3] (C) arr[3][2] (D) arr[2][1] Answer: arr[1][2] Q14. What is the default value of an uninitialized array in C? (A) 0 (B) 1 (C) Random memory value (D) -1 Answer: Random memory value Q15. How does C handle array index out of bounds errors during runtime? (A) Generates a compile-time error (B) Automatically corrects the index (C) Generates a runtime error (D) Does not check for bounds Answer: Does not check for bounds Q16. In C, can an array be resized after its declaration? (A) Yes (B) No (C) Only if it's a dynamic array (D) Only in C99 standard Answer: No Q17. What will be the output of the following C code? int main() { int arr[] = {1, 2, 3, 4, 5}; printf("%d", arr[3]); return 0; } (A) 1 (B) 2 (C) 3 (D) 4 Answer: 4 Q18. What is the output of this C code? int main() { int arr[5] = {1, 2, 3}; printf("%d", arr[4]); return 0; } (A) 0 (B) 3 (C) Random value (D) Error Answer: 0 Q19. What does the following C code do? int main() { int arr[3][4] = {{1, 2}, {3, 4}}; printf("%d", arr[1][1]); return 0; } (A) Prints 2 (B) Prints 3 (C) Prints 4 (D) Prints 0 Answer: Prints 4 Q20 Complete the C code: int main() { int arr[5]; for(int i = 0; i < 5; i++) { ___ } printf("%d", arr[2]); return 0; } (A) arr[i] = i; (B) arr[i] = i * 2; (C) arr[i] = i + 1; (D) arr[i] = 0; Answer: arr[i] = i;