Describe how the 1-D integer array s[4] in v7 is laid out in main memory (i.e.,
ID: 3909552 • Letter: D
Question
Describe how the 1-D integer array s[4] in v7 is laid out in main memory (i.e., RAM). What is contained at s?
// Pointers and arrays
#include <stdio.h>
int main()
{
int s[4];
s[0] = 100;
s[1] = 200;
s[2] = 300;
s[3] = 400;
printf("%d ",s[0]);
printf("%d ",s[1]);
printf("%d ",s[2]);
printf("%d ",s[3]);
printf("%d ",*s);
printf("%d ",*(s+1));
printf("%d ",*(s+2));
printf("%d ",*(s+3));
*s = 1000;
*(s+1) = 2000;
*(s+2) = 3000;
*(s+3) = 4000;
printf("%d ",*s);
printf("%d ",*(s+1));
printf("%d ",*(s+2));
printf("%d ",*(s+3));
}
Explanation / Answer
In memory: s is an array. Structure of S in memory is -------------------------------------------- | Address | x | x + 4 | x + 8 | x + 12 | -------------------------------------------- | Values | s[0] | s[1] | s{2} | s{3} | -------------------------------------------- Where x is the initial address of the array. ====================================================== Final values of the array is [1000,2000,3000,4000]