TRT
Sign in
easyFoundationsconcept

Arrays versus pointers: are they the same?

Explain that arrays and pointers are distinct types, though arrays often decay into pointers.

TRT practice prompt — not a verified question from a named employer.

The Runtime Theory Team2 min read
Learn it firstLists of Data: ArraysLearn how to store multiple values of the same type in an array, access elements by index, and loop through arrays safely.

A strong answer

A strong candidate frames Arrays versus pointers: are they the same? around the exact memory layout, compiler semantics, and hardware execution model covered in Lists of Data: Arrays. Explain that arrays and pointers are distinct types, though arrays often decay into pointers.

Suppose you are writing a program to record the exam scores of 30 students and compute the class average and highest score. With only individual variables, you would have to declare 30 separate identifiers:

Even if you had the patience to type 30 declarations, you could not write a for loop to step through score0, score1, score2, because variable names disappear when the program compiles—you cannot compute a variable name like score + i at runtime. And if next semester's class has 150 students, you would have to rewrite the entire program.

In a production interview, always connect the specification rule to its concrete runtime consequence: state what lives on the stack versus the heap or static storage segment, how the compiler or operating system validates alignments, lifetimes, and error codes, and what happens under adversarial or boundary inputs (such as zero-length buffers, integer overflow, concurrent mutation, or partial I/O). Backing your explanation with a small trace of register/memory state transitions immediately separates senior systems engineers from candidates who only memorized syntax.

What the interviewer is listening for

  • Mastery of core invariant: Declare and initialize an array of a fixed size.
  • Mastery of core invariant: Access and modify array elements using index notation [i].
  • Mastery of core invariant: Loop through an array to read or process all elements.
  • Hardware and ABI awareness: Explaining how sizes, alignments, calling conventions, or kernel boundaries behave on real 64-bit targets rather than relying on implementation-defined assumptions.
  • Defensive engineering: Naming the exact compiler flags (-Wall -Wextra -Werror), static analyzers, or runtime sanitizers (-fsanitize=address,undefined,thread) that verify correctness in CI.

Common mistakes

  • Explaining only surface syntax without tracing the underlying memory addresses, ownership lifetime, or kernel/user-space state transitions.
  • Assuming undefined behavior (such as signed overflow, uninitialized reads, strict-aliasing violations, or dangling pointers) will "just work" because it passed an unoptimized -O0 debug build.
  • Ignoring return codes, partial reads/writes, alignment padding, or cleanup paths when an allocation or syscall fails midway through a function.

This answer walks

Practice follow-ups

  1. 01What does sizeof return for an array versus a pointer?
  2. 02What is array-to-pointer decay?

Not started

Sign in to save your learning progress.

Sign in to save