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?
BeginnerShow 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?
BeginnerShow answer & explanation
`&`
The `&` operator is the address-of operator; `*` is the dereference operator.
Q3. If `p = &x`, which expression is equal to `x`?
BeginnerShow answer & explanation
`*p`
`&` and `*` are inverses: if `p = &x`, then `*p` is the same as `x`.
Q4. What does `int *p;` declare?
BeginnerShow 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?
BeginnerShow 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?
BeginnerShow 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?
BeginnerShow 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.
BeginnerShow 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`?
IntermediateShow 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?
IntermediateShow 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?
IntermediateShow 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?
IntermediateShow 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?
IntermediateShow 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?
IntermediateShow 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`?
IntermediateShow 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?
IntermediateShow 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; } ```
AdvancedShow 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; } ```
AdvancedShow 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; } ```
AdvancedShow 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; } ```
AdvancedShow 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; } ```
AdvancedShow 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.
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