Apr 5, 2012 at 1:24pm UTC
Both work, but I can't remember why. It's still not very useful to use though. Very difficult to read.
Apr 5, 2012 at 2:19pm UTC
The output is absolutely correct
b[i] is equivalent to *(b+i)
i[b] is also equivalent to *(i+b)
Hence b[i] and i[b] will produce the same output
Apr 5, 2012 at 4:05pm UTC
hey thanks for reply,
if i am right, b[i] is understood by compiler as, *(address of b + i (into)size of each element of b) right?
so wont i[b] be *(address of i + b*size of i) ... but that doesn't make any sense, does it?
so i guess i am wrong in my understanding of b[i] ... please correct me ...
*(b+i) ... i know what * does, but how is the (b+i) part calculated?
Apr 5, 2012 at 5:20pm UTC
Why would i[b] be *(address of i +...)? You don't take the address of i do you?
The types of b and i are independent of the place they hold in the expression.
Apr 6, 2012 at 1:29pm UTC
What happens is, that the compiler adds two numbers and returns the adress of that piece of memory. b is some number like 0x33ff99 (a whole bunch of zero and ones) and the other one is 0x000000 through 0x000004. With printf you pick that piece of memory and print its value