Learn C MCQs
Prepare C MCQs (Multiple choice Questions) for exam and job interviews.
What is the purpose of the `sizeof` operator?
1) To determine the size of a variable in bytes
2) To allocate memory
3) To count the number of elements in an array
4) To find the length of a string
Answer : To determine the size of a variable in bytes
Which of the following will not compile in C?
1) int x = 5;
2) int x = "5";
3) int x = (int)5;
4) int x;
Answer : int x = "5";
What is the output of printf("%d", 3 * (2 + 1));?
1) 6
2) 9
3) 3
4) 8
Answer : 9
Which of the following is a correct way to declare a constant?
1) const int x = 10;
2) #define x 10
3) int x = 10;
4) Both 1 and 2
Answer : Both 1 and 2
What will be the output of printf("%d", 5 * 2 + 3 * 2);?
1) 16
2) 18
3) 14
4) 10
Answer : 16
Which of the following is true about function overloading in C?
1) It is supported.
2) It is not supported.
3) It requires different function names.
4) None of the above
Answer : It is not supported.
What is the purpose of the `static` keyword in C?
1) To define a constant
2) To allocate memory
3) To limit the scope of a variable
4) To create a global variable
Answer : To limit the scope of a variable
Which of the following will not produce a syntax error?
1) int x = 5;
2) int 5x = 5;
3) float x = "5.0";
4) char x = 5;
Answer : int x = 5;
What is the output of printf("%d", 2 * 3 - 4 / 2);?
1) 5
2) 4
3) 6
4) 3
Answer : 5
Which of the following is a valid way to declare a multi-dimensional array?
1) int arr[3][4];
2) int arr[4][3];
3) Both 1 and 2
4) None of the above
Answer : Both 1 and 2