# [ACCEPTED]-use of sizeof operator-sizeof

Score: 15

int *p[10]; is an array of pointers.

*p is the first element 10 of that array of pointers. So it is a pointer 9 to an integer. It is not an integer.

int array[] = {23,34,12,17,204,99,16}; is 8 an array of integers. So array[0] is the first element 7 of that array. So it is an integer.

The 6 size of a pointer to an integer (*p) and an 5 integer (array[0]) are different.

So sizeof(*p) and sizeof(array[0]) are different.

sizeof(p) gives 4 the size of the array of pointers. So it 3 is: 10 x 8 = 80.
i.e. (number of elements) x (size of one element)

sizeof(array) gives the 2 size of the array of integers. So it is: 7 1 x 4 = 28.

Score: 3

In the first example, the element is a pointer 3 to int, while in the second example it's 2 just int. You can see that the pointer has 1 8 bytes, the int just 4 bytes.

Score: 1

In the first case, you've created an array 2 of pointers to int, so their size is 8, not 1 4.

Score: 1

In the first example the size of a pointer 3 is used and in the second the size of an 2 integer. They may have different sizes especially 1 on 64 bit systems.

Score: 1

array[0] has type int

*p has type int*

This perhaps demonstrates 3 the stylistic folly of writing

int *p[10] ;

rather than 2

int* p[10] ;

where the second makes it clearer that int* is 1 the type of the array being declared.

Score: 0

The 64-bit environment sets int to 32 bits 5 and long and pointer to 64 bits ..

*p is 4 a pointer - 8 bytes
sizeof(p) -is size 3 of 10 pointers - so 80 bytes

Chances are 2 you have AMD64 machine - check this for 1 details (including other options) http://gcc.gnu.org/onlinedocs/gcc/i386-and-x86_002d64-Options.html

More Related questions