View Single Post
  #6 (permalink)  
Old February 22nd, 2004, 11:53 PM
davekw7x davekw7x is offline
Authorized User
 
Join Date: Feb 2004
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?



Reply With Quote