0 votes 0 votes #include<stdio.h> int main() { int *p; p = (int *)malloc(20); printf("%d\n", sizeof(p)); free(p); return 0; } malloc(20) reserves 20 bytes, why output is 8? Programming in C programming-in-c + – manisha11 asked Sep 17, 2018 edited Oct 17, 2018 by Mk Utkarsh manisha11 371 views answer comment Share Follow See all 4 Comments See all 4 4 Comments reply sakharam commented Sep 17, 2018 reply Follow Share p is an integer pointer that stores addresses. In your system, the compiler uses an 8 byte pointer. In C, you need to manually keep track of the data lenth. Even though you try to find the sizeof(*p) you will obtain the size of the first integer(in this case) = sizeof(int). 0 votes 0 votes manisha11 commented Sep 17, 2018 reply Follow Share Size of int and size of int pointer should not be equal? 0 votes 0 votes sakharam commented Sep 17, 2018 reply Follow Share Size of every type of pointer is same because they all store addresses. The only reason we have different type of pointer is because thats how the compiler knows how much data should be accessed at once. There is no relation between size of int and size of int pointer. It can be different or same depends on the platform (which includes processor, OS, compiler, compiler-options, etc). 4 votes 4 votes manisha11 commented Sep 17, 2018 reply Follow Share Thanks a lot 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes sizeof(int *) is storing address of memory which is pointing to integer data but at last it is storing memory address so it depends on your machine 64 bit or 32 bit machine sizeof(int ) is size of integer your compiler is supporting Dharmendra Lodhi answered Sep 17, 2018 Dharmendra Lodhi comment Share Follow See all 0 reply Please log in or register to add a comment.