Difficulty: Easy
Correct Answer: array
Explanation:
Introduction / Context:
Understanding how arrays relate to pointers is essential in C and C++. Many operations such as passing arrays to functions depend on this relationship. A common interview question is which expression yields the address of the first element of an array. This question tests whether you know how array names decay to pointers in expressions.
Given Data / Assumptions:
Concept / Approach:
In most expressions, the name of an array decays to a pointer to its first element. For int array[10]; the identifier array is converted to a value of type pointer to int that points to array[0]. Therefore, array and &array[0] have the same numeric address value, though their types are slightly different. By contrast, array[0] itself is the first element, not the address. array[1] is the second element, and array(2) is not valid C or C++ array syntax. Recognising this decay rule is key to understanding parameter passing and pointer arithmetic.
Step-by-Step Solution:
Step 1: Note that array[0] refers to the first element itself. Its type is int, not pointer to int.
Step 2: The address of that element is obtained as &array[0].
Step 3: In many contexts, such as function arguments or assignments to pointer variables, the array name array decays to a pointer to its first element.
Step 4: Therefore, array evaluates to the same address value as &array[0] when used in these expressions.
Step 5: Among the options, array is the expression that represents the address of the first element.
Verification / Alternative check:
You can verify this by writing code such as int array[10]; int* p = array; and then printing p and &array[0]. Both addresses will match. If you instead print array[0], you will see the integer stored in that element, not the address. This confirms the conceptual rule that the array name decays to a pointer to the first element in most expressions.
Why Other Options Are Wrong:
Option a, array[0], refers to the value stored in the first element rather than its address. Option b, array[1], is the second element, and its address is not the base address of the array. Option c, array(2), uses function call syntax and is not valid array indexing in C or C++. Only array on its own naturally provides the address of the first element when used in pointer contexts.
Common Pitfalls:
A common source of confusion is mixing up the element and its address, especially when passing arrays to functions. Remember that in function parameters like void f(int a[]), the parameter is actually treated as int* a, reflecting this decay. Understanding that array and &array[0] represent the same memory location helps avoid pointer arithmetic mistakes.
Final Answer:
The expression that gives the memory address of the first element is array.
Discussion & Comments