array size of int and empty array

How do you find array size?

1
2
3
int array[] = {1,2,3,4};
size_t x = sizeof(array)/sizeof(int);
cout<<x;

2

why?


1
2
3
int array[3];
array[0] = 1;
array[2] = 2;

how to know if only 2 of the 3 array has been used only and array[1] is garbage value.
How do you find array size?

1
2
3
4
int array[] = {1,2,3,4};
size_t x = sizeof(array)/sizeof(int);
cout<<x;

2


why?



Are you sure??
I bet everybody else gets 4.
jackel7777 wrote:
how to know if only 2 of the 3 array has been used only and array[1] is garbage value.

You can't. Its up to you to keep your data valid.
Last edited on
Topic archived. No new replies allowed.