Can u tell me what is the difference between sizeof(x)
and sizeof(p_x)
in the code below?
int x[10], *p_x;
p_x = (int*)malloc(10 * sizeof(int));
sizeof(x)
is giving the number of bytes used by the array x
.
sizeof(p_x)
is giving the number of bytes used by a pointer.
#include<stdio.h>
int main() {
int x[10], *p_x;
printf ("%lu %lu\n", (unsigned long)sizeof(x), (unsigned long)sizeof(p_x));
return 0;
}
Program output:
40 4
My MSVC uses 32-bit pointers and 32-bit ints.
EDIT improved number formatting following below comments, thanks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With