212k views
3 votes
Consider int ia[2], *ip; ip = &ia; ia[0] = 1; ia[1]=2; *ip = *(ip+1); What is the value of ia[0]?

User Houbie
by
8.8k points

1 Answer

6 votes

Final answer:

The value of ia[0] is 2.

Step-by-step explanation:

The given code snippet declares an integer array ia of size 2 and a pointer variable ip. The statement ip = &ia assigns the address of the array ia to the pointer ip. The next two statements assign the values 1 and 2 to the elements of the array ia.

The expression *ip = *(ip+1) copies the value of the second element of the array ia (i.e., 2) to the first element of the array ia. Therefore, the value of ia[0] is 2.

User DasIch
by
9.4k points

Related questions