73.2k views
0 votes
Int a[10];

int* ptr;
ptr = a;
What does ptr[1] equal?
a) a[1]
b) a + 1
c) &a[1]
d) ptr + 1

User Winton
by
7.9k points

1 Answer

1 vote

Final answer:

In C programming, ptr[1] represents the value of the second element of the array, which is 'a[1]'.

Step-by-step explanation:

The code provided is a classic example of working with arrays and pointers in C programming. The statement int a[10]; defines an array of 10 integers, while int* ptr; declares a pointer to an integer. The assignment ptr = a; sets the pointer ptr to point at the first element of the array a. When we use the syntax ptr[1], it is equivalent to accessing the second element of the array, just like a[1]. Hence, ptr[1] is the value of the second element of the array a[1].

User Rakesh Kashyap
by
8.3k points