Relationship Between Arrays and Pointers Interview Questions: Model Answers in C

Learn a precise way to explain arrays and pointers in C, then test it against worked address traces, parameter mutation, 2D arrays, and bounds questions.

KnowledgeGate Team

Exam prep & CS education

Updated 22 Nov 20266 min read
Relationship Between Arrays and Pointers Interview Questions: Model Answers in C

A candidate says “an array is a pointer” because a and &a[0] often print the same address, then gets stuck on sizeof a, &a + 1, function parameters, or a 2D array. The reliable model separates the declared object, array-to-pointer conversion, resulting type, arithmetic step, and valid bounds. The examples trace five integers from illustrative address 0x1000, mutate an array through a function parameter, and reach a matrix row at 0x200C.

Are arrays and pointers the same in C?

The model answer is: “No. An array is a fixed-size object containing contiguous elements. In most expressions, an array expression is converted to a pointer to its first element. That is why array and pointer syntax can look interchangeable, although their types and operations differ.”

With int a[5];, a is declared as an array of 5 int. It normally converts to an int * pointing at a[0], but the declaration creates no pointer object. In two important non-conversion contexts, sizeof a examines the whole array and &a takes its address.

The rule a[i] == *(a + i) holds when i designates an array element. It describes expression semantics, not the array object's type. The Arrays and Pointers in C guide develops this distinction further. The earlier Call by Value, Address and Reference interview questions post owns C's value and pointer-parameter semantics; array decay, pointer types, and multidimensional row stride are developed here.

Worked address trace: one array, two pointer types and five values

Use int a[5] = {7, 11, 13, 17, 19}; int *p = a;. Only for this illustration, assume sizeof(int) = 4, sizeof(int *) = 8, and &a[0] = 0x1000.

Expression

Type after any conversion

Illustrative value

Result

a

int *

0x1000

&a[0]

&a[0]

int *

0x1000

&a[0]

p

int *

0x1000

stored pointer

a + 2

int *

0x1008

&a[2]

*(a + 2)

int

13

a[2]

p[3]

int

17

a[3]

&a

int (*)[5]

0x1000

whole array

a + 1

int *

0x1004

one int

&a + 1

int (*)[5]

0x1014

five int objects

Thus sizeof a = 5 x 4 = 20 bytes, while sizeof p = 8 here. Despite equal addresses, int * steps by one int; int (*)[5] by the array. p++ is valid in range. a++ and a = p are invalid because an array is not a modifiable pointer.

Diagram of a five-element int array showing element addresses, pointer types, pointer steps, and illustrative sizeof values.

Six array-pointer interview questions with compact model answers

Question

Short answer

Follow-up proof

Why does a[i] work?

It means *(a + i).

+ i selects an element; * reads it.

Does i[a] compile?

Yes, as *(i + a).

Addition is commutative; a[i] remains clearer.

Can the array name be reassigned or incremented?

No; a pointer variable can.

An array is not a modifiable pointer.

Why can sizeof a differ from sizeof p?

One sees an array, one a pointer.

sizeof does not convert the array here.

What differs between a and &a?

Their types and steps differ.

+ 1 skips an element or a whole array.

Can one-past-the-end be used?

Form it for same-array comparison or subtraction, but never dereference it.

It names no element.

For int b[4] = {2, 4, 6, 8}; int *q = b + 1;, *q is 4, *(q + 2) is 8, and q[-1] is 2. All designate elements of b. Give rule and reason.

Why an array parameter behaves like a pointer

Consider this call:

c
void bump(int x[4], size_t n) {
    if (n > 1) x[1] += 10;
    x++;
}

int a[4] = {3, 5, 7, 9};
bump(a, 4);

Here int x[4] is adjusted to int *x. The update changes the caller's array to {3, 15, 7, 9}, while x++ changes only the local pointer copy.

Writing [4] here does not transmit length. Inside bump, sizeof x is sizeof(int *), not 4 * sizeof(int), so the caller must pass n or another bound. In this parameter position, void read(int x[], size_t n) and void read(int *x, size_t n) declare the same adjusted type. This equivalence does not apply outside function parameters. Arrays and Strings in C: Decay, sizeof and 2D Addresses provides more traces.

The 2D-array follow-up: why int [2][3] does not become int **

Use int m[2][3] = {{1, 2, 3}, {4, 5, 6}};. For this drawing only, assume sizeof(int) = 4 and &m[0][0] = 0x2000. The expression m normally converts to a pointer to its first row, with type int (*)[3]. One m + 1 step therefore skips 3 x 4 = 12 bytes and reaches 0x200C.

Now compute m[1][2] = *(*(m + 1) + 2). First, m + 1 identifies row 1 at 0x200C. That row expression leads to its first element, and adding 2 reaches m[1][2] at 0x2014. Dereferencing gives 6.

An int ** is wrong here because it describes a pointer to a pointer. It does not carry the fixed three-int row stride of this contiguous matrix. The matching parameter forms are void show(size_t rows, int m[][3]) and void show(size_t rows, int (*m)[3]). Both retain the column count required for row arithmetic.

Diagram of a 2 by 3 int matrix showing row stride, element addresses, pointer-to-row type, and the m[1][2] calculation.

Pointer arithmetic, bounds and string traps

Return to the five-element a under the same illustrative assumptions: 4-byte int, 8-byte pointer, and base address 0x1000. The one-past pointer a + 5 may be formed and has the shown address 0x1014, but *(a + 5) has undefined behaviour. a + 5 and &a + 1 can share that numeric address while having different types and arising from different arithmetic.

Subtraction within the array counts elements: &a[4] - &a[1] = 4 - 1 = 3, not 12 bytes. Pointer subtraction or relational ordering across unrelated arrays is not valid portable reasoning.

Now compare char s[] = "CAT"; with const char *t = "CAT";. The object s is a four-element array containing {'C', 'A', 'T', '\0'}, so s[0] = 'B' is valid. The pointer t points at a string literal, and code must not attempt t[0] = 'B'. A string literal is not a modifiable heap or stack buffer.

How interviews test arrays and pointers at different depths

Interviewers can stop at different points, so practise a progression from definition to output trace, parameter mutation, 2D-array type, then a bounds and undefined-behaviour follow-up.

Use this sequence: declaration -> decay context -> resulting type -> step size -> bounds -> value. A closed-book drill:

  1. For int b[4] = {10, 20, 30, 40}; int *q = &b[3];, q - b is 3 because subtraction counts elements.

  2. sizeof b / sizeof b[0] is 4 in the declaring scope. It cannot recover the length from a function's adjusted int b[] parameter.

  3. With int (*r)[4] = &b;, the statement (*r)[2] = 99; changes b to {10, 20, 99, 40}.

Use the Arrays and Pointers in C: 10 Solved MCQs as a closed-book check: state each rule before viewing its solution.

Arrays and pointers in C: the short version and next step

Test

Rule

Ask

Object or expression

An array expression usually decays.

Did it decay?

a or &a

Types set steps.

Element or whole array?

sizeof

Array size differs from pointer size.

Operand type?

Parameter

Adjusts to a pointer.

Bound source?

2D array or int **

Fixed row width, not pointer chain.

Row stride?

Checksum: 13, 20, 0x1004 versus 0x1014, {3, 15, 7, 9}, and 6 at 0x2014. Explain each. Next: C Language course for fundamentals, Interview & Resume Preparation Course for delivery, or All Courses and Exams for the wider route.