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

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

ID: 3769398 • Letter: Q

Question

Q: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.

--------------------------------------------------------------------------------------------------------------------------------------------------------------

I answerd this question as the following but Im not sure if Im in the right track or not...

My Answer:

**Because it is a 32-bit machine, so int = 4bytes , char=1 bytes , pointer=4bytes

1- variable a:sizeof(char) >> 1 bytes

2- variable b:sizeof(char *)>> 1*4(pointer)>>4 bytes

3- variable c:sizeof(char *)>> 1*4(pointer)>>4 bytes

4- variable d:2*sizeof(int)>> 2*4(int size)>> 8 bytes

5- variable e:sizeof(int *) >> 4*4(pointer)>>8 bytes

6- variable i:sizeof(int) >> 4 bytes

7- variable j:sizeof(int *) >> 4*4(pointer)>>8 bytes

Explanation / Answer

Pointer is always of the same size, it does not vary with data types. It varies with type of machine.

char a; 1 byte

char*b,*c are of 4 bytes each(on 32 bit memory)

int d[2] -> 4 bytes

int *e -> 4 bytes

int i -> 2 bytes

int *j -> 4 bytes