Pointers in C Language with Examples: 21 MCQs with answers

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

Warm-up · 8 questions

Q1. Which statement best describes what a pointer stores?

Beginner
A A memory address B A character constant C A floating-point value D A copy of a struct
Show answer & explanation

A memory address

A pointer is a variable whose value is a memory address, not a data value.

Q2. Which operator returns the address of a variable?

Beginner
A `->` B `*` C `%` D `&`
Show answer & explanation

`&`

The `&` operator is the address-of operator; `*` is the dereference operator.

Q3. If `p = &x`, which expression is equal to `x`?

Beginner
A `*x` B `*p` C `&p` D `p`
Show answer & explanation

`*p`

`&` and `*` are inverses: if `p = &x`, then `*p` is the same as `x`.

Q4. What does `int *p;` declare?

Beginner
A `p` is an array of ints B `p` is a function returning int C `p` is an `int` variable D `p` is a pointer to an `int`
Show answer & explanation

`p` is a pointer to an `int`

Read `int *p` as 'p is a pointer to int'.

Q5. What does `NULL` mean for a pointer?

Beginner
A It points to nothing B It points to the stack C It points to the first array element D It points to address 0x1
Show answer & explanation

It points to nothing

`NULL` is the special constant meaning 'points to nothing'.

Q6. Which pair of functions manages dynamic memory through pointers?

Beginner
A `strlen` and `strcpy` B `malloc` and `free` C `fopen` and `fclose` D `printf` and `scanf`
Show answer & explanation

`malloc` and `free`

`malloc` allocates memory and returns a pointer; `free` releases it.

Q7. Which data structures are built from pointers linking nodes?

Beginner
A Only floating-point matrices B Only character variables C Linked lists, trees, and graphs D Only integer arrays
Show answer & explanation

Linked lists, trees, and graphs

Linked lists, trees, and graphs are built from pointers linking nodes.

Q8. In C, `arr[i]` is defined to be exactly equivalent to `*(arr + i)`, which is why array indexing and pointer arithmetic are interchangeable.

Beginner
A True B False
Show answer & explanation

True

In C, `arr[i]` is defined to be exactly equivalent to `*(arr + i)`, which is why array indexing and pointer arithmetic are interchangeable.

Building up · 8 questions

Q9. In `int *a, b;`, what is `b`?

Intermediate
A A pointer to pointer B A plain `int` C An array of ints D A pointer to int
Show answer & explanation

A plain `int`

The `*` binds to the variable name, so only `a` is a pointer; `b` is a plain int.

Q10. What happens when you dereference a `NULL` pointer?

Intermediate
A It returns 0 safely B It allocates memory automatically C Undefined behaviour, usually a crash D It prints the address
Show answer & explanation

Undefined behaviour, usually a crash

Dereferencing `NULL` causes undefined behaviour, typically a crash.

Q11. How does an array name behave when used in an expression?

Intermediate
A It becomes a copy of the whole array B It becomes the array's length C It decays to a pointer to its first element D It becomes a `NULL` pointer
Show answer & explanation

It decays to a pointer to its first element

An array name decays to a pointer to its first element, so `arr` behaves like `&arr[0]`.

Q12. Which expression is exactly equivalent to `arr[i]` in C?

Intermediate
A `*(arr + i)` B `&arr[i]` C `arr + i` D `*arr + i`
Show answer & explanation

`*(arr + i)`

The C standard defines `arr[i]` as exactly `*(arr + i)`.

Q13. If `p` points to an `int`, how far does `p + 1` advance?

Intermediate
A By 8 bytes always B By the size of the whole array C By one `int` (typically 4 bytes) D By exactly 1 byte
Show answer & explanation

By one `int` (typically 4 bytes)

Pointer arithmetic advances in units of the pointed-to type, not bytes.

Q14. Why does C pass a pointer to a function when the function must modify the caller's variable?

Intermediate
A Because C passes arguments by value B Because pointers are always faster C Because arrays cannot be passed D Because functions cannot return values
Show answer & explanation

Because C passes arguments by value

C passes arguments by value, so a function gets a copy; passing the address lets it modify the original.

Q15. What is `int **pp`?

Intermediate
A A function returning int B A pointer to a pointer to int C A pointer to an int array D An array of two ints
Show answer & explanation

A pointer to a pointer to int

`int **pp` stores the address of another pointer, i.e. a pointer to pointer.

Q16. What is a C string essentially?

Intermediate
A An `int *` ending in 0 B A `void *` with no terminator C A fixed-size struct D A `char *` ending in `'\0'`
Show answer & explanation

A `char *` ending in `'\0'`

A C string is essentially a `char *` ending in the null character `'\0'`.

Topper level · 5 questions

Q17. Given the following code snippet, what will be the output when the program is executed? ```c #include <stdio.h> void modify(int *p) { *p += 10; } int main(void) { int x = 5; modify(&x); printf("%d\n", x); return 0; } ```

Advanced
A 20 B 10 C 15 D 5
Show answer & explanation

15

The function `modify` takes a pointer to `int`, dereferences it, and adds 10 to the value pointed to. Since `x` is initially 5, after calling `modify(&x)`, `x` becomes 15.

Q18. Consider the following code snippet. What will be the value of `*p` after the execution? ```c #include <stdio.h> #include <stdlib.h> int main(void) { int *p; *p = 42; printf("%d\n", *p); return 0; } ```

Advanced
A 42 B Undefined Behavior C Segmentation Fault D 0
Show answer & explanation

Segmentation Fault

The pointer `p` is uninitialized and points to a random memory location. Dereferencing it with `*p = 42;` leads to a segmentation fault, as it attempts to write to an invalid address.

Q19. What will be the output of the following code snippet? ```c #include <stdio.h> void swap(int **a, int **b) { int *temp = *a; *a = *b; *b = temp; } int main(void) { int x = 1, y = 2; int *px = &x, *py = &y; swap(&px, &py); printf("%d %d\n", *px, *py); return 0; } ```

Advanced
A 2 1 B 2 2 C 1 2 D 1 1
Show answer & explanation

2 1

The function `swap` takes pointers to pointers and swaps the addresses they point to. After the swap, `px` points to `y` and `py` points to `x`, resulting in the output `2 1`.

Q20. Given the following code, what will be the output of the program? ```c #include <stdio.h> int main(void) { int arr[3] = {1, 2, 3}; int *p = arr + 1; printf("%d\n", *(p - 1) + *(p + 1)); return 0; } ```

Advanced
A 6 B 3 C 5 D 4
Show answer & explanation

4

Here, `p` points to the second element of `arr`, which is `2`. The expression `*(p - 1)` accesses the first element (`1`), and `*(p + 1)` accesses the third element (`3`). Thus, `1 + 3` equals `4`.

Q21. What will happen if the following code is executed? ```c #include <stdio.h> #include <stdlib.h> int main(void) { int *p = malloc(sizeof(int)); *p = 10; free(p); printf("%d\n", *p); return 0; } ```

Advanced
A Segmentation Fault B 10 C Undefined Behavior D 0
Show answer & explanation

Undefined Behavior

After calling `free(p);`, the memory allocated for `p` is released back to the system. Dereferencing `p` afterwards results in undefined behavior because `p` now points to a deallocated memory.

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