Quick Kit: 38 MCQs with answers

All 38 multiple-choice questions from this kit, free and with no sign-up.

Warm-up · 19 questions

Q1. Which of the following is a valid variable name in C?

Beginner
A 2nd_value B _myVar C int D my-var
Show answer & explanation

_myVar

Variable names in C must start with a letter or underscore. `_myVar` starts with an underscore, making it valid. `2nd_value` starts with a digit, `my-var` contains a hyphen, and `int` is a reserved keyword.

Q2. What will be the output of the following code? ```c int x = 5; int y = x++; printf("%d %d", x, y); ```

Beginner
A 5 6 B 6 5 C 5 5 D 6 6
Show answer & explanation

6 5

The post-increment operator `x++` uses the current value of `x` (5) in the assignment to `y`, then increments `x` to 6. So `x` becomes 6 and `y` is 5.

Q3. Which loop is guaranteed to execute its body at least once?

Beginner
A `for` loop B `while` loop C `do-while` loop D All loops guarantee at least one execution
Show answer & explanation

`do-while` loop

The `do-while` loop checks the condition after executing the body, so it always runs at least once. `for` and `while` loops check the condition before execution, so they may run zero times.

Q4. What does the following code print? ```c int arr[] = {10, 20, 30}; int *ptr = arr; printf("%d", *(ptr + 1)); ```

Beginner
A 30 B 10 C 20 D The memory address of the second element
Show answer & explanation

20

`ptr` points to the first element of `arr`. `ptr + 1` moves the pointer to the next integer (20), and `*(ptr + 1)` dereferences it to get the value 20.

Q5. Which function is used to read a string including spaces from standard input?

Beginner
A `gets` B `fgets` C `puts` D `scanf`
Show answer & explanation

`fgets`

`fgets` reads a line of text including spaces and is safer than `gets` because it limits the number of characters read. `scanf` with `%s` stops at whitespace, and `puts` is for output.

Q6. What is the output of the following code? ```c int a = 10, b = 20; if (a = b) { printf("Equal"); } else { printf("Not Equal"); } ```

Beginner
A Compilation error B Not Equal C Undefined behavior D Equal
Show answer & explanation

Equal

The condition `a = b` is an assignment, not a comparison. It assigns the value of `b` (20) to `a`. In C, any non-zero value is considered true, so the `if` block executes and prints "Equal". This is a common mistake.

Q7. Which header file is required for using `malloc` and `free`?

Beginner
A `<math.h>` B `<string.h>` C `<stdio.h>` D `<stdlib.h>`
Show answer & explanation

`<stdlib.h>`

The functions `malloc`, `calloc`, `realloc`, and `free` are declared in the `` header file.

Q8. What is the output of the following recursive function for `n = 5`? ```c int fact(int n) { if (n == 0) return 1; return n * fact(n - 1); } ```

Beginner
A 720 B 15 C 120 D 25
Show answer & explanation

120

The function calculates the factorial of `n`. `fact(5)` = 5 * 4 * 3 * 2 * 1 = 120.

Q9. Which of the following correctly declares a pointer to an integer?

Beginner
A `int *ptr;` B `pointer int ptr;` C `int ptr;` D `int &ptr;`
Show answer & explanation

`int *ptr;`

In C, a pointer is declared by placing an asterisk (`*`) between the data type and the variable name. `int *ptr;` declares `ptr` as a pointer to an integer.

Q10. In C, the `&&` operator returns true if at least one operand is true.

Beginner
A True B False
Show answer & explanation

False

The `&&` (logical AND) operator returns true only if both operands are true. The `||` (logical OR) operator returns true if at least one operand is true.

Q11. A string in C can be modified after it is created using a character array.

Beginner
A True B False
Show answer & explanation

True

If a string is stored as a character array (e.g., `char str[] = "Hello";`), its individual characters can be modified. However, string literals (e.g., `char *str = "Hello";`) are usually stored in read-only memory and should not be modified.

Q12. The ___ operator is used to access the members of a structure through a pointer.

Beginner
Show answer & explanation

—

The arrow operator (`->`) is used to access members of a structure when you have a pointer to the structure. The dot operator (`.`) is used when you have the structure variable itself.

Q13. A ___ loop is best suited when the number of iterations is known in advance.

Beginner
Show answer & explanation

—

The `for` loop is ideal when you know exactly how many times you want to iterate, as it combines initialization, condition, and increment in one line.

Q14. What is a null pointer and why is it useful?

Beginner
Show answer & explanation

—

This checks foundational knowledge of pointer initialization and safety.

Q15. What is the purpose of the `break` statement in a `switch` statement?

Beginner
Show answer & explanation

—

This checks understanding of control flow in `switch` statements.

Q16. What is an array in C and how are its elements accessed?

Beginner
Show answer & explanation

—

This checks foundational knowledge of arrays.

Q17. What is the output of `printf("%d", sizeof(char));` and why?

Beginner
Show answer & explanation

—

This checks understanding of the `sizeof` operator and the `char` data type.

Q18. What is a structure in C and how do you access its members?

Beginner
Show answer & explanation

—

This checks foundational knowledge of structures.

Q19. What is the difference between `getchar` and `putchar`?

Beginner
Show answer & explanation

—

This tests basic knowledge of character I/O functions.

Building up · 12 questions

Q20. Explain the difference between the prefix and postfix increment operators in C.

Intermediate
Show answer & explanation

—

This tests understanding of operator side effects and expression evaluation order.

Q21. How does a `for` loop differ from a `while` loop in terms of structure and typical use cases?

Intermediate
Show answer & explanation

—

This tests understanding of loop constructs and their appropriate applications.

Q22. Explain the concept of passing by value in C functions.

Intermediate
Show answer & explanation

—

This tests understanding of function parameter semantics.

Q23. What is the difference between `fprintf` and `fscanf`?

Intermediate
Show answer & explanation

—

This tests understanding of file I/O functions.

Q24. Describe the difference between `calloc` and `malloc`.

Intermediate
Show answer & explanation

—

This tests understanding of dynamic memory allocation functions.

Q25. How do you declare a function that takes an array as a parameter?

Intermediate
Show answer & explanation

—

This checks understanding of array parameter passing.

Q26. Explain the concept of recursion and provide a simple example.

Intermediate
Show answer & explanation

—

This tests understanding of recursive problem-solving.

Q27. Consider the following C code snippet: ```c int a = 5, b = 10; int result = a++ + --b; printf("%d %d %d", a, b, result); ``` What is the output?

Intermediate
A 6 10 15 B 6 9 14 C 5 9 14 D 6 9 15
Show answer & explanation

6 9 15

The expression `a++` is post-increment, so it uses the current value of `a` (5) in the addition, then increments `a` to 6. `--b` is pre-decrement, so it first decrements `b` to 9, then uses that value. Thus `result = 5 + 9 = 14`. After the expression, `a` is 6 and `b` is 9. The output is `6 9 14`.

Q28. Which of the following correctly describes the behavior of the `continue` statement inside a `for` loop?

Intermediate
A It terminates the loop immediately. B It skips the rest of the current iteration and proceeds to the next iteration, including the increment expression. C It restarts the loop from the beginning. D It skips the rest of the current iteration and proceeds to the next iteration without executing the increment expression.
Show answer & explanation

It skips the rest of the current iteration and proceeds to the next iteration, including the increment expression.

In a `for` loop, `continue` skips the remaining statements in the current iteration and then executes the increment expression (the third part of the `for` header) before checking the condition again. This is a key difference from a `while` loop, where `continue` skips directly to the condition check.

Q29. What is the output of the following code? ```c #include <stdio.h> void swap(int x, int y) { int temp = x; x = y; y = temp; } int main() { int a = 3, b = 7; swap(a, b); printf("%d %d", a, b); return 0; } ```

Intermediate
A 7 3 B 7 7 C 3 3 D 3 7
Show answer & explanation

3 7

C uses pass-by-value, meaning the function `swap` receives copies of `a` and `b`. Any changes to `x` and `y` inside the function do not affect the original variables `a` and `b` in `main`. Therefore, `a` remains 3 and `b` remains 7.

Q30. Given the declaration `int arr[] = {2, 4, 6, 8};` and `int *p = arr;`, which expression correctly accesses the value `6`?

Intermediate
A *(p + 2) B *(p + 3) C p[3] D *(arr + 3)
Show answer & explanation

*(p + 2)

In C, array indexing starts at 0. The value `6` is at index 2. Since `p` points to the first element (`arr[0]`), `p + 2` points to `arr[2]`, and dereferencing it with `*` gives the value `6`. The other options point to index 3, which is `8`.

Q31. What is the output of the following code? ```c #include <stdio.h> int main() { int x = 0; if (x = 1) { printf("True"); } else { printf("False"); } return 0; } ```

Intermediate
A Undefined behavior B Compilation error C False D True
Show answer & explanation

True

The condition `x = 1` is an assignment, not a comparison. In C, an assignment expression evaluates to the assigned value (1 in this case). Since 1 is non-zero, it is considered true, so the `if` block executes and prints `True`. This is a common pitfall where `=` is used instead of `==`.

Topper level · 7 questions

Q32. Explain the concept of pointer arithmetic with an example.

Advanced
Show answer & explanation

—

This tests deeper understanding of pointers and memory layout.

Q33. What is the purpose of the `const` keyword when used with a pointer?

Advanced
Show answer & explanation

—

This tests understanding of pointer qualifiers and their effects.

Q34. Consider the following C code snippet: ```c #include <stdio.h> int main() { int a = 5, b = 10; int result = a++ + --b; printf("%d %d %d", a, b, result); return 0; } ``` What is the output?

Advanced
A 6 9 14 B 5 9 14 C 6 9 15 D 6 9 14
Show answer & explanation

6 9 14

The expression `a++ + --b` is evaluated as follows: `--b` decrements `b` to 9 (pre-decrement), then `a++` uses the current value of `a` (5) and increments `a` to 6 (post-increment). So `result = 5 + 9 = 14`. After the line, `a` is 6, `b` is 9, and `result` is 14. The correct output is "6 9 14".

Q35. Given the declaration `int arr[] = {2, 4, 6, 8};` and `int *p = arr;`, which expression correctly accesses the value `6`?

Advanced
A `*(p + 3)` B `*(arr + 3)` C `p[3]` D `*(p + 2)`
Show answer & explanation

`*(p + 2)`

The array `arr` has elements at indices 0, 1, 2, 3. The value `6` is at index 2. Since `p` points to the first element (`arr[0]`), `p + 2` points to the third element (index 2), and dereferencing it with `*` gives `6`. Option `*(arr + 3)` would give `8`, `p[3]` is equivalent to `*(p+3)` which gives `8`, and `*(p + 3)`…

Q36. What is the output of the following code? ```c #include <stdio.h> void swap(int x, int y) { int temp = x; x = y; y = temp; } int main() { int a = 3, b = 7; swap(a, b); printf("%d %d", a, b); return 0; } ```

Advanced
A 3 7 B 7 7 C 3 3 D 7 3
Show answer & explanation

3 7

In C, arguments are passed by value. The `swap` function receives copies of `a` and `b` (i.e., `x` and `y`). Swapping `x` and `y` inside the function does not affect the original variables `a` and `b` in `main()`. Therefore, after the call, `a` remains 3 and `b` remains 7. The output is "3 7".

Q37. What is the output of the following code? ```c #include <stdio.h> int main() { int x = 0; if (x = 1) { printf("True"); } else { printf("False"); } return 0; } ```

Advanced
A Compilation error B True C Undefined behavior D False
Show answer & explanation

True

The condition `if (x = 1)` uses the assignment operator `=`, not the comparison operator `==`. This assigns the value `1` to `x`, and the expression evaluates to `1` (true). In C, any non-zero value is considered true, so the `if` block executes, printing "True". This is a common pitfall.

Q38. Consider the following C code that attempts to read a string including spaces: ```c #include <stdio.h> int main() { char str[50]; printf("Enter a string: "); scanf("%s", str); printf("%s", str); return 0; } ``` If the user enters "Hello World", what will be printed?

Advanced
A World B Hello C Nothing (empty string) D Hello World
Show answer & explanation

Hello

The `%s` format specifier in `scanf` reads a sequence of non-whitespace characters. It stops reading at the first whitespace (space, tab, newline). So when the user types "Hello World", only "Hello" is stored in `str`, and the output is "Hello". To read a line including spaces, one should use `fgets` or `scanf("%[^\n]"…

Make your own

Your notes can be a kit like these

Every kit here was made from real study material. Point Veda at a chapter, a PDF, a photo or a link and get notes, flashcards, practice MCQs, games and a scored test — free, in 42 languages.

  • Chapter notes
  • Flashcards
  • Practice MCQs
  • Scored tests
  • Exam prep

Get Veda free See what students get

Free to start · No ads · Works in 42 languages