How to calculate sizeof() in c programming manually (without using computer)?? H
ID: 3708370 • Letter: H
Question
How to calculate sizeof() in c programming manually (without using computer)??
Here are some examples, I don't know how these answers (sizeof) were calculated??
(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
#define my_sizeof(type) (char *)(&type+1)-(char*)(&type)
int main()
{
double x;
printf("%d", my_sizeof(x));
getchar();
return 0;
}
######################################################################
int main()
{
int arr[] = {1, 2, 3, 4, 7, 98, 0, 12, 35, 99, 14};
printf("Number of elements :%d", sizeof(arr)/sizeof(arr[0]));
return 0;
}
############################################################################
int *ptr = malloc(10*sizeof(int));
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.