Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

sizeof expertise

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?

Name: Anonymous 2011-12-17 5:58

>>1
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.

>>2
This is a coincidence -- 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.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List