Learn C MCQs

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

Which of the following is a valid way to open a file in C?

1) fopen("file.txt", "r");

2) open("file.txt", "r");

3) file.open("file.txt", "r");

4) None of the above

Answer : Option 1

What does the `return` statement do in a function?

1) Exits the function and returns control to the calling function.

2) Returns the value to the calling function and continues execution.

3) Stops the program execution.

4) None of the above

Answer : Option 1

How do you properly free allocated memory in C?

1) free(ptr);

2) delete(ptr);

3) deallocate(ptr);

4) None of the above

Answer : Option 1

Which of the following is the correct way to initialize a pointer?

1) int *p = &x;

2) int p = &x;

3) int *p = x;

4) None of the above

Answer : Option 1

What does the `sizeof` operator return when applied to a variable?

1) The size of the variable in bytes.

2) The address of the variable.

3) The length of the variable.

4) None of the above

Answer : Option 1

Which of the following is not a valid C data type?

1) int

2) float

3) integer

4) char

Answer : Option 3

What is the purpose of the `continue` statement in C?

1) To terminate the loop.

2) To skip the remaining code in the current iteration and start the next iteration.

3) To exit the current function.

4) None of the above

Answer : Option 2

What is the correct way to write a multi-line comment in C?

1) /* This is a multi-line comment */

2) // This is a multi-line comment

3) /* This is a multi-line comment

4) None of the above

Answer : Option 1

Which keyword is used to define a block of code in C?

1) function

2) block

3) begin

4) None of the above

Answer : Option 4

What will be the output of printf("%d", 10>>2);?

1) 2

2) 40

3) 5

4) None

Answer : Option 1