C Pointers Quiz — 18 Questions with Answers

Test your understanding of C pointers with these 18 multiple-choice questions — dereferencing, pointer arithmetic, pointers and arrays, pointers to functions, and the classic traps. Every question has the answer and a short explanation hidden below it, and the trickier ones link to a full walkthrough with compilable code.

These questions come from our free Android app, C Programming Quiz — 150+ questions across 9 categories with score tracking, if you prefer to practise on your phone.

How to use this page: answer each question yourself before tapping Show answer. If you get one wrong, follow the linked explanation — knowing why the wrong options are wrong is what interviews test.

Question 1 of 18 (Easy)

What is the output of this code?

int a = 10;
int *p = &a;
printf("%d", *p);
  1. 10
  2. Address of a
  3. Garbage value
  4. Compile error
Show answer

Answer: A — 10

p stores the address of a; dereferencing it with *p reads the value stored there, which is 10.

Full walkthrough with compilable code: read the detailed explanation.

Question 2 of 18 (Medium)

Which statement about a null pointer is correct?

  1. It is guaranteed not to point to any object
  2. It points to the first byte of the program
  3. It points to a random address
  4. It always points to the top of the stack
Show answer

Answer: A — It is guaranteed not to point to any object

A null pointer compares unequal to a pointer to any object. Dereferencing it is undefined behavior. It is the canonical 'points to nothing valid' value.

Question 3 of 18 (Medium)

What is the output of this code?

int arr[] = {1, 2, 3};
int *p = arr;
printf("%d", *(p + 1));
  1. 1
  2. 2
  3. 3
  4. An address
Show answer

Answer: B — 2

p points to arr[0]. p + 1 points to arr[1] (pointer arithmetic scales by element size), so *(p + 1) is 2.

Full walkthrough with compilable code: read the detailed explanation.

Question 4 of 18 (Medium)

What does the declaration 'int **p;' mean?

  1. A pointer to a pointer to int
  2. A pointer to an int array
  3. Two integer pointers
  4. An invalid declaration
Show answer

Answer: A — A pointer to a pointer to int

Each * adds one level of indirection. 'int **p' is a pointer to a pointer to int.

Question 5 of 18 (Medium)

What is the output of this code?

char *s = "abc";
printf("%c", *(s + 2));
  1. a
  2. b
  3. c
  4. abc
Show answer

Answer: C — c

s points to the start of the string. s + 2 points to the third character, so *(s + 2) is 'c'.

Full walkthrough with compilable code: read the detailed explanation.

Question 6 of 18 (Hard)

What is the output of this code?

int a = 5, b = 10;
int *p = &a, *q = &b;
*p = *q;
printf("%d %d", a, b);
  1. 5 10
  2. 10 10
  3. 10 5
  4. 5 5
Show answer

Answer: B — 10 10

*p = *q copies the value at q (10) into the location p points to (a). So a becomes 10; b is unchanged.

Full walkthrough with compilable code: read the detailed explanation.

Question 7 of 18 (Hard)

What is the output of this code?

int arr[] = {10, 20, 30};
int *p = arr + 2;
printf("%d", p[-1]);
  1. 10
  2. 20
  3. 30
  4. Undefined behavior
Show answer

Answer: B — 20

p points to arr[2]. Negative index p[-1] is valid here because it stays within the array bounds — it accesses arr[1] which is 20.

Full walkthrough with compilable code: read the detailed explanation.

Question 8 of 18 (Medium)

What does a function pointer declaration 'int (*fp)(int, int);' mean?

  1. fp is a pointer to a function taking two ints and returning int
  2. fp is a function returning a pointer to int
  3. fp is an array of function pointers
  4. fp is an invalid declaration
Show answer

Answer: A — fp is a pointer to a function taking two ints and returning int

The parentheses around *fp make fp a pointer. The full type is: pointer to function(int, int) returning int.

Question 9 of 18 (Easy)

What operator gives the address of a variable?

  1. *
  2. &
  3. ->
  4. @
Show answer

Answer: B — &

The address-of operator & gives the memory address where a variable is stored.

Question 10 of 18 (Hard)

What is the output of this code?

int x = 42;
void *vp = &x;
printf("%d", *(int *)vp);
  1. 42
  2. Address of x
  3. Compile error
  4. Undefined behavior
Show answer

Answer: A — 42

void* is a generic pointer. Casting it back to int* and dereferencing retrieves the original value 42. This is a valid pattern.

Full walkthrough with compilable code: read the detailed explanation.

Question 11 of 18 (Hard)

What is the output of this code?

int a[3] = {1, 2, 3};
printf("%d", 2[a]);
  1. 1
  2. 2
  3. 3
  4. Compile error
Show answer

Answer: C — 3

a[2] and 2[a] are identical — both expand to *(a + 2) = *(2 + a). This is a valid, if unusual, feature of C's array indexing.

Full walkthrough with compilable code: read the detailed explanation.

Question 12 of 18 (Medium)

What is the size of a pointer on a 64-bit system?

  1. 2 bytes
  2. 4 bytes
  3. 8 bytes
  4. Depends on the type pointed to
Show answer

Answer: C — 8 bytes

On a 64-bit platform, all pointers are 8 bytes regardless of what type they point to (int*, char*, void*, etc.).

Question 13 of 18 (Hard)

What is the output of this code?

int a = 1, b = 2;
void swap(int *x, int *y) {
    int t = *x; *x = *y; *y = t;
}
swap(&a, &b);
printf("%d %d", a, b);
  1. 1 2
  2. 2 1
  3. Compile error
  4. Undefined behavior
Show answer

Answer: B — 2 1

Passing addresses lets swap modify the caller's variables. After the swap, a=2 and b=1.

Full walkthrough with compilable code: read the detailed explanation.

Question 14 of 18 (Medium)

What is the output of this code?

int a = 10;
int *p = &a;
(*p)++;
printf("%d", a);
  1. 10
  2. 11
  3. Compile error
  4. Undefined behavior
Show answer

Answer: B — 11

(*p)++ increments the value at the address p points to. Since p points to a, a becomes 11.

Full walkthrough with compilable code: read the detailed explanation.

Question 15 of 18 (Hard)

What is the output of this code?

char *arr[] = {"foo", "bar", "baz"};
printf("%s", arr[1]);
  1. foo
  2. bar
  3. baz
  4. Compile error
Show answer

Answer: B — bar

arr is an array of char pointers. arr[1] is the pointer to "bar". %s prints until the null terminator, giving "bar".

Full walkthrough with compilable code: read the detailed explanation.

Question 16 of 18 (Medium)

What is the output of this code?

int x = 5;
int *p = &x;
printf("%d", sizeof(p));
  1. 4
  2. 8
  3. 5
  4. Depends on the value of x
Show answer

Answer: B — 8

sizeof(p) gives the size of the pointer itself, not the value it points to. On a 64-bit system all pointers are 8 bytes.

Full walkthrough with compilable code: read the detailed explanation.

Question 17 of 18 (Hard)

Which is the correct way to declare a pointer to a const int?

  1. const int *p
  2. int const* p
  3. Both A and B are equivalent
  4. int *const p
Show answer

Answer: C — Both A and B are equivalent

'const int *p' and 'int const *p' are identical — both declare a pointer to a read-only int. 'int *const p' is a const pointer to (modifiable) int — different thing.

Question 18 of 18 (Easy)

What is the output of this code?

int x = 7;
int *p = &x;
printf("%d", *p + 1);
  1. 7
  2. 8
  3. Address of x + 1
  4. Compile error
Show answer

Answer: B — 8

*p dereferences p to get 7, then + 1 gives 8. The pointer itself is not moved.

Full walkthrough with compilable code: read the detailed explanation.

How Did You Score?

All 18 correct means this topic is interview-ready — try the harder timed rounds in the C Programming Quiz app. Missed a few? The guides below cover everything these questions test.

Keep Practising

More C Quizzes