Find the address of an index in an array in C -


given definition of array in c: int a[2][3][4][5], , address of a[0][0][0][0] 1000 address of a[1][1][1][1], assuming int occupies 4 bytes.

i got:

(3*4*5 * 4bytes) + (4*5 * 4bytes) + (5* 4bytes) + 4bytes = 344

344 + 1000 = 1344 location of a[1][1][1][1]

but have no idea if i'm right. math seemed sound me.

just print adress of variable see it!:

#include <stdio.h>    int main() {      int a[2][3][4][5];      printf ("size of int %d\n", sizeof(int));      printf("adress of frist element \t%p\n", &a[0][0][0][0]);     printf("adress of x element \t\t%p\n", &a[1][1][1][1]);      printf ("in decimal: \t\t\t%d\n", &(a[0][0][0][0]));     printf ("in decimal: \t\t\t%d\n", &(a[1][1][1][1]));      printf("difference between adresses %d", (char *)&a[1][1][1][1] - (char *)&a[0][0][0][0]);         return 0;  } 

after can check if right!

and see right! it's 334


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -