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

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

ID: 3769158 • Letter: C

Question

Consider the following variable definitions:

char a, *b, *c;

int d[2], *e;

int i, *j;

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

a   sizeof(char)

b   sizeof(char *)

c   sizeof(char *)

d   2*sizeof(int)

e   sizeof(int *)

i   sizeof(int)

j   sizeof(int *)

Total number of bytes for each?

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

j = &i;

*j = 50;              /* i = 50 */

e = &d[0];

*e = 20;              /* d[0] = 20 */

e[1] = 30;                /* d[1] = 30 */

j = &d[1];               

*j = i+d[1];          /* d[1] = 80 */

printf(“d = [%d, %d]n”, d[0], d[1]);

char a, *b, *c;

int d[2], *e;

int i, *j;

Explanation / Answer

a) 4 Bytes

b) 4 Bytes

c) 4 Bytes

d) 8 Bytes

e) 4 Bytes

i) 4 Bytes

j) 4 Bytes

d=[20,80]