why will I get 100 , when sizeof(numbers)/sizeof(numbers[0])? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

why will I get 100 , when sizeof(numbers)/sizeof(numbers[0])?

28th Jan 2017, 10:22 AM
Monisha Mp
Monisha Mp - avatar
8 Answers
+ 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.
28th Jan 2017, 11:00 AM
Petr Hatina
Petr Hatina - avatar
+ 1
can u brief it out?
28th Jan 2017, 11:05 AM
Monisha Mp
Monisha Mp - avatar
+ 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.
28th Jan 2017, 12:19 PM
Arpan Lunawat
Arpan Lunawat - avatar
+ 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?
28th Jan 2017, 5:39 PM
Monisha Mp
Monisha Mp - avatar
+ 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);
28th Jan 2017, 5:57 PM
Arpan Lunawat
Arpan Lunawat - avatar
+ 1
thank you
28th Jan 2017, 6:12 PM
Monisha Mp
Monisha Mp - avatar
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.
28th Jan 2017, 5:42 PM
Arpan Lunawat
Arpan Lunawat - avatar
0
an integer size is of 2bytes right?
28th Jan 2017, 5:55 PM
Monisha Mp
Monisha Mp - avatar