How is the 3rd element in an array accessed based on pointer notation?
a) *(arr + 2)
b) *(arr + 3)
c) *(arr + 1)
d) arr[3]
Answer:
a) *(arr + 2)
Explanation:
In C, array elements can be accessed using pointer notation. The 3rd element of an array arr
is accessed using *(arr + 2)
, where arr
is the base address of the array, and adding 2 moves the pointer to the third element. This pointer arithmetic is a powerful feature of C that allows direct memory manipulation.
Understanding pointer notation is crucial for efficient array manipulation and memory management in C programming.