Learn C MCQs
Prepare C MCQs (Multiple choice Questions) for exam and job interviews.
Which of the following is the correct syntax for a do-while loop?
1) do {} while (condition);
2) do while (condition) {}
3) while (condition) do {}
4) Both 1 and 2
Answer : do {} while (condition);
What does the `sizeof` operator return for an array?
1) Number of elements
2) Size of the entire array
3) Size of the first element
4) Size of the type
Answer : Size of the entire array
Which of the following functions can be used to convert a string to a floating-point number?
1) atof()
2) strtof()
3) Both 1 and 2
4) None of the above
Answer : Both 1 and 2
What will be the output of printf("%d", 5 ^ 2);?
1) 7
2) 3
3) 5
4) 1
Answer : 7
Which of the following is used to declare a pointer in C?
1) type *pointer;
2) type pointer;
3) pointer *type;
4) type &pointer;
Answer : type *pointer;
What is the output of printf("%d", 10 == 10);?
1) 1
2) 0
3) 10
4) None of the above
Answer : 1
Which of the following is the correct way to declare an enum in C?
1) enum color {red, green, blue};
2) enum color red, green, blue;
3) color enum {red, green, blue};
4) None of the above
Answer : enum color {red, green, blue};
What will be the output of printf("%d", 4 * (3 + 2));?
1) 20
2) 24
3) 15
4) 12
Answer : 20
What is the correct way to define a structure in C?
1) struct name {int x;};
2) struct {int x;} name;
3) Both 1 and 2
4) None of the above
Answer : struct name {int x;};
What is the output of printf("%d", 1 << 3);?
1) 3
2) 4
3) 8
4) 2
Answer : 8