What is the difference between sizeof (x) and sizeof (p_x)

Can I say 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));
+4
source share
3 answers
sizeof(x)

sets the number of bytes used by the array x.

sizeof(p_x)

sets the number of bytes used by the 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, thanks.

+9
source
sizeof(x)

- the size of the array object. Its meaning 10 * sizeof (int).

sizeof(p_x) 

- the size of the pointer object. Its meaning sizeof (int *).

+4
source

sizeof (x) (10 * sizeof (int), sizeof int - 4 ), sizeof (p_x) . 64- , 8 , 32- 4 .

+4

All Articles