Well, this is obviously a trick question, since no one
would deliberately do such a thing (!)
However, K&R states "In evaluating a[ i ], C converts it to
*(a+i)." Now, you must believe that; then you can see that
i[ a ] is converted to *(i+a). In both cases, the quantity in
parentheses is a pointer + an integer (the same quantity,
regardless of how you write it). The trick question is designed
to confuse the student (or, maybe, make him think about the
really intimate relationship between pointers and array
indices).
Dave
Quote:
quote:Originally posted by kv_shan
say a[10] is an array of integers,and say i is an integer counter.
to print the array elements we say
for (i=0;i<n;i++)
printf("%d",a[i]);
but what if i say
printf("%d",i[a]) ;
???????????????????????????????????????what is the result and why is it so?
|