Learn C MCQs
Prepare C MCQs (Multiple choice Questions) for exam and job interviews.
What is the default return type of a function in C if no return type is specified?
1) int
2) void
3) float
4) char
Answer : int
Which of the following is a valid way to declare a string in C?
1) char str[100];
2) char str[];
3) char *str;
4) All of the above
Answer : All of the above
What does the `strlen()` function do?
1) Calculates the length of a string
2) Concatenates two strings
3) Copies one string to another
4) Converts string to integer
Answer : Calculates the length of a string
What will be the output of printf("%d", 10 / 3);?
1) 3
2) 4
3) 2
4) 3.33
Answer : 3
Which of the following is not a valid C data type?
1) int
2) float
3) char
4) string
Answer : string
What is the output of printf("%d", 4 + 5 * 2);?
1) 14
2) 13
3) 9
4) 10
Answer : 14
Which of the following is used for dynamic memory allocation in C?
1) malloc()
2) calloc()
3) free()
4) All of the above
Answer : All of the above
What will be the output of printf("%d", 5 << 1);?
1) 10
2) 5
3) 15
4) 20
Answer : 10
What is the correct way to declare a function in C?
1) int func()
2) func() int
3) void func()
4) Both 1 and 3
Answer : Both 1 and 3
Which of the following operators is used to access members of a union?
1) .
2) ->
3) ::
4) Both 1 and 2
Answer : Both 1 and 2