Name: Anonymous 2011-12-17 5:16
int *p;
int a[1000];If
a and p are exactly the same fucking thing (a pointer to an integer), why do sizeof p and sizeof a differ?
int *p;
int a[1000];a and p are exactly the same fucking thing (a pointer to an integer), why do sizeof p and sizeof a differ?
sizeof a = 1000*(sizeof p)sizeof assumes you're using a pointer to point at just one location of data and gives you the pointer size. When using an array, you probably aren't interested in the pointer it really represents. Remember, it's an operator, not a function; the behaviour can get pretty weird.sizeof(p) is uintptr_t (usually 4), sizeof(a) is 1000 * sizeof(int) (usually 4000). If these were char *p and char c[1000], results would be 4 and 1000, for example.