How to get the value of sizeof() by hand? (Please, I don\'t want any codes, I ju
ID: 3708504 • Letter: H
Question
How to get the value of sizeof() by hand? (Please, I don't want any codes, I just want to know how can the attached outputs calculated by hand)
I have an exam tomorrow and still don't understand how to calculate the size of an array, pointer,... by hand
(5 points) What's the output of this code snippet? (%zu prints a value of unsigned long integer, %p prints the address of a pointer) int (*p)[10]; p malloc(sizeofin) * 20); assume malloc() is successful printf"'sizeofp) %zum", sizeofp)); printf"sizeof*p)-%zuln", sizeof(*p)); printf("pl-%pm", (void *)p++); printf"p2 %pin", (void *)p); Output: sizeof(p) (1 point) sizeof(*p) - 40 (2 points)Explanation / Answer
1)
sizeof(p) = 8 bytes = pointer size (common)
sizeof(*p) = 40 = pointer holds 10 values ;each of int type i.e 4 bytes .So;total is 10*4 = 40 bytes
2)
sizeof(a) = 8 bytes = pointer size (common) = starting base of array is pointer
sizeof(b) = 8 bytes = pointer size (common) = starting base of array is pointer
sizeof(*a) = 4 bytes = pointer a holds address of integer value; so *a = int value = 4 bytes
sizeof(*b) = 4 bytes = pointer b holds address of integer value; so *b = int value = 4 bytes
sizeof(*c) = 4 bytes = pointer b holds address of integer value; so *b = int value = 4 bytes
3)
a) sizeof(p) = 8 bytes = pointer size (common)
b)
sizeof(a) = 240 bytes = size of the structure array = size of structure * 10 = sum of size of each element in structure * 10
sizeof(q) = 8 bytes = pointer size(common)
sizeof(*p) = 24 bytes = p holds the address of one element of the structure array .So, *p = value of one element of structure whose size is 24
sizeof(*q->next) = 24 bytes = q->next holds the address of one element of the structure array .So, *q->next = value of one element of structure whose size is 24
sizeof(25.3) = 8 bytes = 25.3 is a double value which is of 8 bytes
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.