Learn C MCQs
Prepare C MCQs (Multiple choice Questions) for exam and job interviews.
Which of the following is a valid comment in C?
1) // This is a comment
2) /* This is a comment */
3) /* This is a comment
4) // This is a comment */
Answer : All of the above
What is the output of printf("%d", 5 | 3);?
1) 5
2) 7
3) 1
4) 3
Answer : 7
Which of the following is used to declare a function with variable arguments in C?
1) va_list
2) stdarg.h
3) va_start()
4) All of the above
Answer : All of the above
What will be the output of printf("%d", 5 + 10 * 2);?
1) 25
2) 30
3) 20
4) 25
Answer : 25
What is the correct way to declare a pointer to an integer in C?
1) int *ptr;
2) int ptr*;
3) int &ptr;
4) pointer int ptr;
Answer : int *ptr;
Which of the following is true about `static` variables?
1) They retain their value between function calls.
2) They are initialized at runtime.
3) They are local to a function.
4) Both 1 and 3
Answer : Both 1 and 3
What will be the output of printf("%d", (1 + 2) * (3 + 4));?
1) 21
2) 28
3) 18
4) 24
Answer : 21
What is the output of printf("%d", 7 / 2);?
1) 3
2) 4
3) 2
4) 3.5
Answer : 3
Which of the following is the correct syntax to declare a union in C?
1) union name {int a; float b;};
2) union {int a; float b;};
3) union name {int a; float b;};
4) Both 1 and 3
Answer : Both 1 and 3
What is the output of printf("%d", 10 ^ 3);?
1) 9
2) 11
3) 1
4) 10
Answer : 9