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: 3769030 • 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

Consider the following variable definitions:
char a, *b, *c;(1+2+2)
int d[2], *e;(4+2)
int i, *j;(2+2)

How many total bytes does this code allocate for variables?
Assume a 32-bit representation
for integer and pointer values.
char a, *b, *c;(1+2+2)-->5
int d[2], *e;(4+2)-->6
int i, *j;(2+2)-->4

Total-->15


a sizeof(char)--1
b sizeof(char *)--2
c sizeof(char *)--2
d 2*sizeof(int)--4
e sizeof(int *)--2
i sizeof(int)--2
j sizeof(int *)--2

Total number of bytes for each?-->15 bytes
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] ”, d[0], d[1]);
OUTPUT:d=[20, 80]