Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following variable definitions: int d[3], *e; int i, *j; char a, *b

ID: 3832384 • Letter: C

Question

Consider the following variable definitions:

int d[3], *e;
int i, *j;
char a, *b, c[3];

a) How many total bytes does this code allocate for variables? Assume a 32-bit representation for integer and pointer values. Explain your answer.

b) What is the output of the following piece of code? (Use the above variable definitions). Show your work.

e = d;
j = &i;
*j = 10;
*e = 20;
e++;
e[1] = 30;
*e = i;
for(i = 1; i < 3; i++)
   d[i] = d[i] + d[i-1];

*e = i;
printf(“d = [%d, %d, %d] ”, d[0], d[1], d[2]);

Explanation / Answer

1.

since it is 32 bit representation of int ie. 4 bytes

for int d[3] it takes 3*4 = 12 bytes

int *e --------- 4 bytes

int i ------ 4 bytes

int *j ------ 4 bytes

char a----- 1 bytes

char *b --- 4 bytes

char c[3] --- 3 bytes

2. output is

20 3 60