c++ - Why is x[0] != x[0][0] != x[0][0][0]? -


i'm studying little of c++ , i'm fighting pointers. understand can have 3 level of pointers declaring:

int *(*x)[5]; 

so *x pointer array of 5 elements pointers int. know x[0] = *(x+0);, x[1] = *(x+1)and on....

so, given above declaration, why x[0] != x[0][0] != x[0][0][0] ?

x pointer array of 5 pointers int.
x[0] array of 5 pointers int.
x[0][0] pointer int.
x[0][0][0] int.

                       x[0]    pointer array  +------+                                 x[0][0][0]          x -----------------> |      |         pointer int           +-------+                0x500 | 0x100| x[0][0]---------------->   0x100 |  10   | x pointer    |      |                                  +-------+ array of 5        +------+                         pointers int      |      |         pointer int                                             0x504 | 0x222| x[0][1]---------------->   0x222                                          |      |                                                                   +------+                                                                   |      |         pointer int                                              0x508 | 0x001| x[0][2]---------------->   0x001                                          |      |                                                                   +------+                                                                   |      |         pointer int                                              0x50c | 0x123| x[0][3]---------------->   0x123                                          |      |                                                                   +------+                                                                   |      |         pointer int                                              0x510 | 0x000| x[0][4]---------------->   0x000                                          |      |                                                                   +------+                                              

you can see

  • x[0] array , converted pointer first element when used in expression (with exceptions). therefore x[0] give address of first element x[0][0] 0x500.
  • x[0][0] contains address of int 0x100.
  • x[0][0][0] contains int value of 10.

so, x[0] equal &x[0][0]and therefore, &x[0][0] != x[0][0].
hence, x[0] != x[0][0] != x[0][0][0].


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -