Learn C MCQs
Prepare C MCQs (Multiple choice Questions) for exam and job interviews.
How do you declare a function pointer in C?
1) int (*funcPtr)();
2) int funcPtr();
3) int funcPtr;
4) None of the above
Answer : int (*funcPtr)();
Which operator is used to access a member of a structure through a pointer?
1) .
2) ->
3) :
4) &
Answer : ->
Which loop structure is guaranteed to execute at least once?
1) for
2) while
3) do-while
4) None of the above
Answer : do-while
Which keyword is used to define a recursive function in C?
1) recurse
2) function
3) None of the above
4) recursive
Answer : None of the above
What is the correct way to declare a void pointer?
1) void ptr;
2) void *ptr;
3) ptr void;
4) None of the above
Answer : void *ptr;
How do you correctly allocate memory dynamically in C?
1) int *ptr = alloc(10);
2) int ptr = malloc(10);
3) int *ptr = malloc(10 * sizeof(int));
4) None of the above
Answer : int *ptr = malloc(10 * sizeof(int));
Which of the following operators has the highest precedence in C?
1) +
2) *
3) =
4) ()
Answer : ()
Which function is used to read a single character from a file in C?
1) getc()
2) fgetc()
3) read()
4) fgetchar()
Answer : fgetc()
Which of the following is true about a union?
1) It can store multiple data types simultaneously.
2) It can store only one value at a time.
3) It allocates memory separately for each member.
4) None of the above
Answer : It can store only one value at a time.
What is the return value of malloc() when memory allocation fails?
1) NULL
2) 0
3) Garbage value
4) None of the above
Answer : NULL