0
why will I get 100 , when sizeof(numbers)/sizeof(numbers[0])?
8 Antworten
+ 1
There is not visible what type is number. In case the number is an araray[100], this result is OK, this is a simple mathematic.
+ 1
can u brief it out?
+ 1
If number is an Array of 100 characters then it will give 100.
In case of Intergers (int) it will give 400 on a 32 bit machine.
+ 1
#include <iostream>
using namespace std;
int main()
{
int numbers[100];
cout << sizeof(numbers) / sizeof(numbers[0]);
return 0;
}
will I get to know how its 100?
+ 1
No, You must be using a 32 bit compiler and there the Integer size is 4 bytes.
You can verify this by
int a;
cout<<sizeof(a);
+ 1
thank you
0
Yes,
sizeof(numbers) i. e. the Whole Array Give 400 as there are 100 integers in array each taking 4 bytes of memory 100*4 = 400.
Now sizeof(numbers[0]) is only 4 bytes because it is only One element of the Array.
So, 400/4 gives you 100 in Output.
0
an integer size is of 2bytes right?