Understanding pointer arithmetic and array addressing in C++
This hard C++ question tests your grasp of pointer arithmetic and how the language distinguishes between pointers to arrays and pointers to array elements. It is the kind of low-level memory question that quant trading firms use to verify you can reason precisely about address calculations—critical when optimizing tight loops or debugging memory-layout issues.
The question asks you to predict the numeric address that results from two superficially similar operations on an array pointer. The key insight is that pointer arithmetic scales by the size of the type being pointed to. When you add 1 to a pointer, the CPU moves forward by sizeof(type) bytes, not by 1 byte. The distinction between these two expressions hinges on whether you are incrementing a pointer to the array itself or a pointer to its first element—a subtle but consequential difference in C++.
- Pointer-to-array vs. pointer-to-element type distinctions
- Scaling of pointer arithmetic by underlying type size
- Address representation and integer casting