Top 100 MCQs with answers on C Programming for Problem Solving, covering both overview and arrays topics:
1–25: Overview of C
1. Which of the following is the correct syntax to include a header file in C?
A) #include <stdio.h>
B) include <stdio.h>
C) #include stdio.h
D) #include "stdio.h"
Answer: A
2. Which is not a valid variable name in C?
A) int_1
B) 1int
C) _int
D) intNum
Answer: B
3. What is the keyword used to define a constant in C?
A) const
B) constant
C) final
D) #define
Answer: A
4. What is the default return type of a C program if not specified?
A) int
B) float
C) void
D) char
Answer: A
5. Which function is used to display output in C?
A) scanf()
B) printf()
C) print()
D) output()
Answer: B
6. What will be the result of: 5 + 2 * 3?
A) 21
B) 11
C) 15
D) 10
Answer: B
7. Which operator is used to get the remainder in C?
A) /
B) %
C) //
D) rem
Answer: B
8. What is the output of
int x = 5/2;
printf("%d", x); ?
A) 2
B) 2.5
C) 3
D) Error
Answer: C
9. Which of these is not a loop construct in C?
A) for
B) do
C) while
D) repeat
Answer: D
10. What will if(0) execute?
A) True
B) False
C) Error
D) Depends on compiler
Answer: B
11. How many times will a do-while loop run if the condition is false at first check?
A) 0
B) 1
C) Infinite
D) Depends
Answer: B
12. Which symbol is used for 'logical AND'?
A) &&
B) &
C) ||
D) and
Answer: A
13. What is the correct syntax for a while loop?
A) while (condition) { }
B) while condition()
C) while {condition}
D) loop while (condition)
Answer: A
14. Which keyword is used to come out of a loop?
A) stop
B) return
C) break
D) exit
Answer: C
15. Which of these is used for multi-way branching?
A) if
B) for
C) switch
D) do-while
Answer: C
16. Which header file includes input/output functions?
A) stdio.h
B) conio.h
C) stdlib.h
D) io.h
Answer: A
17. The function used to read a character from user input is:
A) scanf
B) getchar
C) gets
D) printf
Answer: B
18. What is the output of:
int x = 4;
printf("%d", ++x);
A) 4
B) 5
C) Error
D) Undefined
Answer: B
19. What is the value of x after this code?
int x = 10;
x = x + x++;
A) 20
B) 21
C) 22
D) 19
Answer: B
20. Which is the correct syntax for a function declaration?
A) function int sum();
B) int sum();
C) declare sum();
D) func sum();
Answer: B
21. Which data type will be most suitable for storing age (positive numbers only)?
A) int
B) float
C) char
D) short
Answer: A
22. Which format specifier is used to print a float value?
A) %d
B) %f
C) %c
D) %lf
Answer: B
23. How do you declare a constant integer in C?
A) const int x;
B) int const x;
C) #define x 10
D) All of the above
Answer: D
24. Which one is not a valid escape sequence?
A) \n
B) \r
C) \a
D) \e
Answer: D
25. What is the size of int on a 32-bit system?
A) 2 bytes
B) 4 bytes
C) 8 bytes
D) 1 byte
Answer: B
26–50: Arrays and Strings
26. What is the correct syntax to declare an array of 10 integers?
A) int arr(10);
B) int arr[10];
C) int arr{10};
D) int[10] arr;
Answer: B
27. Array index starts from:
A) 1
B) -1
C) 0
D) None
Answer: C
28. What is the output of this code?
int arr[] = {1, 2, 3};
printf("%d", arr[1]);
A) 1
B) 2
C) 3
D) Error
Answer: B
29. What is the output?
char str[] = "Hello";
printf("%s", str);
A) H
B) Hello
C) Error
D) ello
Answer: B
30. What does strlen("Hello") return?
A) 4
B) 5
C) 6
D) Error
Answer: B
31. What is the correct way to declare a 2D array?
A) int a[2][3];
B) int a(2,3);
C) int a{2,3};
D) array int[2][3];
Answer: A
32. What is the default value of an uninitialized array element in C (local scope)?
A) 0
B) Undefined
C) Garbage
D) Null
Answer: C
33. Which function is used to copy strings in C?
A) copy()
B) strcpy()
C) memcpy()
D) strcat()
Answer: B
34. What is the use of strcmp() function?
A) Compares two strings
B) Copies a string
C) Returns string length
D) Joins two strings
Answer: A
35. Which sorting algorithm compares adjacent elements and swaps?
A) Bubble sort
B) Merge sort
C) Insertion sort
D) Selection sort
Answer: A
36. In selection sort, the array is divided into:
A) Sorted and unsorted parts
B) Two equal parts
C) One sorted part
D) Multiple parts
Answer: A
37. Time complexity of linear search is:
A) O(1)
B) O(n)
C) O(log n)
D) O(n log n)
Answer: B
38. Time complexity of bubble sort in worst case:
A) O(n)
B) O(n log n)
C) O(n²)
D) O(1)
Answer: C
39. Which header file is required for strlen() function?
A) stdlib.h
B) stdio.h
C) string.h
D) conio.h
Answer: C
40. What is the maximum number of characters in a string declared as char s[10];?
A) 10
B) 11
C) 9
D) 8
Answer: C (1 byte for \0)
41. Which function is used to join two strings?
A) strcat()
B) strcmp()
C) strjoin()
D) strcpy()
Answer: A
42. In C, strings are terminated with:
A) \0
B) ;
C) .
D) space
Answer: A
43. Which algorithm is not a searching algorithm?
A) Linear search
B) Binary search
C) Bubble sort
D) None
Answer: C
44. Which algorithm uses divide-and-conquer?
A) Merge sort
B) Selection sort
C) Linear search
D) Bubble sort
Answer: A
45. What is the output of this code?
char ch = 'A' + 2;
printf("%c", ch);
A) A
B) B
C) C
D) D
Answer: C
46. What is the result of strcmp("abc", "abd")?
A) 0
B) >0
C) <0
D) Error
Answer: C
47. Which function takes input string including spaces?
A) scanf("%s", str);
B) gets(str);
C) getchar();
D) puts();
Answer: B
48. Which sorting algorithm has best-case time of O(n)?
A) Bubble sort
B) Selection sort
C) Insertion sort
D) Merge sort
Answer: C
49. Which of the following is not a valid string function?
A) strlen()
B) strrev()
C) strcopy()
D) strcat()
Answer: C
50. Which searching algorithm works only on sorted arrays?
A) Linear search
B) Binary search
C) Bubble sort
D) Jump search
Answer: B
51. Which of the following is used to reverse a string in C?
A) reverse()
B) revstr()
C) strrev()
D) None of the above
Answer: C
52. How to pass a 1D array to a function?
A) func(int arr[])
B) func(int *arr)
C) func(int arr[10])
D) All of the above
Answer: D
53. What is the correct way to declare a character array of size 10?
A) char arr[10];
B) char arr(10);
C) char arr{10};
D) character arr[10];
Answer: A
54. What is the result of this code?
char str[] = "ABCD";
printf("%c", str[2]);
A) A
B) B
C) C
D) D
Answer: C
55. What does sizeof("Hello") return?
A) 5
B) 6
C) 7
D) Error
Answer: B
56. Which function is used to read a string from user?
A) gets()
B) scanf()
C) fgets()
D) All of the above
Answer: D
57. What is the time complexity of linear search?
A) O(1)
B) O(n)
C) O(log n)
D) O(n²)
Answer: B
58. What is the time complexity of selection sort in worst case?
A) O(n)
B) O(n log n)
C) O(n²)
D) O(log n)
Answer: C
59. What is the best case time complexity of bubble sort?
A) O(n²)
B) O(log n)
C) O(n)
D) O(1)
Answer: C
60. Can a string in C be modified after declaration?
A) No
B) Yes, if not a string literal
C) Only with const
D) None
Answer: B
61. What does strcat() do?
A) Compares strings
B) Copies strings
C) Appends second string to first
D) None
Answer: C
62. What is the correct syntax to declare a 3x3 matrix?
A) int a[3][3];
B) matrix int[3][3];
C) int matrix(3,3);
D) int[3,3] a;
Answer: A
63. A string literal is stored in:
A) Stack
B) Heap
C) Constant segment
D) Code segment
Answer: C
64. What will this code print?
char a[] = "abc";
printf("%d", sizeof(a));
A) 3
B) 4
C) Error
D) Undefined
Answer: B
65. What does fgets() do?
A) Reads from file
B) Reads from stdin
C) Reads until newline or EOF
D) All of the above
Answer: D
66. Which of the following is not a correct string function in C?
A) strlen()
B) strupr()
C) strcpy()
D) strsum()
Answer: D
67. The memory address of the first element of an array is:
A) base address
B) last address
C) null
D) depends on OS
Answer: A
68. What happens when an array is out of bounds?
A) Compiler error
B) Runtime error
C) Garbage value
D) Memory overflow
Answer: C
69. Can we declare arrays with variable size in C (C99 onwards)?
A) Yes
B) No
C) Only in functions
D) Only with malloc
Answer: A
70. What will this print?
char a[] = "Hello";
printf("%c", *a);
A) H
B) e
C) l
D) o
Answer: A
71. What is a string in C?
A) Array of chars ending with '\0'
B) Object
C) Constant
D) char*
Answer: A
72. Which sorting algorithm is stable?
A) Selection sort
B) Bubble sort
C) Merge sort
D) B and C
Answer: D
73. What is time complexity of binary search?
A) O(n)
B) O(log n)
C) O(n log n)
D) O(n²)
Answer: B
74. Which of the following is not required in binary search?
A) Sorted array
B) Middle element
C) First and last indices
D) Random array
Answer: D
75. Which function compares two strings in a case-sensitive way?
A) strcmp()
B) strcmpi()
C) strncmpi()
D) strcase()
Answer: A
76. How many roots can a quadratic equation have?
A) 0
B) 1
C) 2
D) All of the above
Answer: D
77. What is the discriminant in a quadratic equation?
A) b² - 4ac
B) a² - 4bc
C) c² - 4ab
D) b² + 4ac
Answer: A
78. Which of the following is used to compute binomial coefficient?
A) nCr = n! / (r!(n-r)!)
B) nPr = n! / (n-r)!
C) nCr = n + r
D) None
Answer: A
79. Which loop is best suited for printing Pascal’s triangle?
A) for
B) while
C) do-while
D) All of them
Answer: A
80. In Pascal’s triangle, each element is the:
A) Sum of above two numbers
B) Factorial of index
C) Prime number
D) Constant
Answer: A
81. Which function is used to calculate power in C?
A) pow()
B) power()
C) exp()
D) math()
Answer: A
82. Which library contains pow() function?
A) stdlib.h
B) math.h
C) string.h
D) stdio.h
Answer: B
83. Which statement is used for decision making in C?
A) if
B) switch
C) both A and B
D) loop
Answer: C
84. How many cases can a switch statement have?
A) Only 2
B) Only 1
C) Any number
D) None
Answer: C
85. Which of the following does not return a value?
A) void
B) int
C) float
D) char
Answer: A
86. How many times will the loop run?
for (int i = 0; i < 5; i++)
A) 4
B) 5
C) 6
D) Infinite
Answer: B
87. What is the output of:
int x = 3;
printf("%d", x++);
A) 3
B) 4
C) 2
D) Error
Answer: A
88. What is the output of:
int x = 3;
printf("%d", ++x);
A) 3
B) 4
C) 2
D) Error
Answer: B
89. Which is not a C keyword?
A) auto
B) extern
C) printf
D) register
Answer: C
90. What is the keyword to define user-defined data types?
A) typedef
B) def
C) new
D) struct
Answer: A
91. Which keyword is used for structure in C?
A) class
B) struct
C) object
D) data
Answer: B
92. Which of the following is not a looping statement?
A) for
B) while
C) goto
D) do-while
Answer: C
93. How to define an infinite loop in C?
A) while(1)
B) for(;;)
C) do {} while(1);
D) All of the above
Answer: D
94. What will this code print?
int a = 10, b = 5;
printf("%d", a > b);
A) 0
B) 1
C) True
D) False
Answer: B
95. What does return 0; mean in C main function?
A) End of program
B) Success
C) Error
D) Both A and B
Answer: D
96. What will be the output of printf("%d", sizeof(int)); on 32-bit system?
A) 2
B) 4
C) 8
D) 16
Answer: B
97. Which operator has highest precedence?
A) ()
B) *
C) +
D) =
Answer: A
98. What is ASCII value of 'A'?
A) 64
B) 65
C) 66
D) 67
Answer: B
99. What is the output of printf("%d", 'A');?
A) A
B) 65
C) Error
D) Undefined
Answer: B
100. What is the output?
int a = 5, b = 10;
a = b++;
printf("%d %d", a, b);
A) 10 11
B) 11 10
C) 5 10
D) 10 10
Answer: A