size of a pointer allocated by malloc [duplicate]-Collection of common programming errors
you must be using 64 bit system/OS, thats why it printed 8 for printf(“%d”, sizeof(pointer));
when you declare char *p; it will reserve space equalto sizeof(char *) in you memory.
now if the system is 64-bit it will reserve 8 bytes or if it is 32-bit then it will reserve 4 bytes.
now
char* pointer;
pointer = malloc (20000);
when you define pointer = malloc(20000) it will reserve a block of 20000 bytes in memory where pointer points to the first byte of that block it doesnt allocates 20000 bytes to pointer.