Learn C MCQs

Prepare C MCQs (Multiple choice Questions) for exam and job interviews.

Which of the following is a valid way to declare an array of 5 floats?

1) float arr[5];

2) float arr();

3) float arr = {1.0, 2.0};

4) None of the above

Answer : float arr[5];

What is the purpose of the `break` statement in a loop?

1) To exit the loop

2) To continue to the next iteration

3) To skip the current iteration

4) None of the above

Answer : To exit the loop

Which of the following will not compile in C?

1) int x = 10;

2) int 1x = 10;

3) float y = 5.5;

4) char c = 'A';

Answer : int 1x = 10;

What is the output of printf("%d", 9 % 4);?

1) 2

2) 1

3) 3

4) 0

Answer : 1

Which of the following is used for dynamic memory allocation in C?

1) malloc()

2) alloc()

3) new

4) None of the above

Answer : malloc()

What will be the output of printf("%d", 5 + 3 * 2 - 4);?

1) 9

2) 6

3) 4

4) 5

Answer : 7

Which of the following statements is used to include a header file?

1) #include <header>

2) #include header

3) import header

4) require header

Answer : #include <header>

What is the purpose of the `continue` statement in a loop?

1) To exit the loop

2) To skip to the next iteration

3) To break out of the loop

4) None of the above

Answer : To skip to the next iteration

What will be the output of printf("%d", 3 * 5 - 4);?

1) 11

2) 7

3) 15

4) 12

Answer : 11

Which of the following is a valid pointer declaration?

1) int *ptr;

2) ptr int*;

3) *ptr int;

4) int * ptr;

Answer : int *ptr;