In: Computer Science
Draw a memory layout to show the relations of a, b and c.
char a[3][10] = {"abcdefg", "1234567", "!@#$%^&"};
char* b[3];
char** c;
b[0] = &a[0][0];
b[1] = &a[1][0];
b[2] = &a[2][0];
c = b;
char x = b[0][3];
char y = b[0][13];
Solution
Let's assume array a is stored starting from memory location 100.
Assuming each caracter occupies 1 byte and a pointer occupies 8 bytes.
The three elements of array b are the pointers, which store address of element a[0][0], a[1][0] and a[2][0] respectively.
c stores the starting address of array b.
The memory layout for better understanding is shown below:
char x = b[0][3];
b[0][3] = *(*(b+0)+3)
* represent the value at operator.
*(b+0) = b[0] = 100
b[0][3] = *(*(b+0)+3) = *(100+3) = Value stored at memory location 103 = Character 'c'
char y = b[0][13];
b[0][13] = *(*(b+0)+13)
* represent the value at operator.
*(b+0) = b[0] = 100
b[0][13] = *(*(b+0)+13) = *(100+13) = Value stored at memory location 113 = 4