Consider the following variable definitions:
char a, *b, *c; int d[2], *e; int i, *j; |
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 ?
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]);
size of a sizeof(char) is 1 byte // because character is a data type which requires 1 byte to store data
size of b sizeof(char*) is 4 byte // because it is given that the representation is of 32 bits or 4 bytes
size of c sizeof(char*) is 4 byte
size of d 2*sizeof(int) is 8 byte
size of e sizeof(int*) is 4 byte
size of i sizeof(int) is 4 byte
size of j sizeof(int *) is 4 byte
Therefore the total number of bytes will be (1+4+4+8+4+4+4)bytes=29 bytes.
A. The output of the code will 20,80
Note: If you run the code it will give error . Try printf(“d = %d, %d”, d[0], d[1]); insteads of
printf(“d = [%d, %d]\n”, d[0], d[1]);.
Get Answers For Free
Most questions answered within 1 hours.