Suppose I have the following array:
int list[3]={2,8,9};
printf(\"%p,%p,%p\",(void*)&list[0],(void*)&list[1],(void*)&list[2]);
Is i
Yes, it's guaranteed that &list[0]<&list[1]
and &list[1]<&list[2]
. When pointers to elements of the same array are compared, the pointer to the element with the larger subscript will be considered to have larger value. This is specified in C99 6.5.8@5:
pointers to array elements with larger subscript values compare greater than pointers to elements of the same array with lower subscript values
However, it is not guaranteed that the values printed by printf with %p
will also follow the same ordering - these values are implementation-defined.