sizeof C++ | SoloLearn: Learn to code for FREE!


sizeof C++

int numbers[100]; cout << sizeof(numbers) / sizeof(numbers[0]); // Outputs 100 Why is it 'sizeof(numbers[0])' and not 'sizeof(numbers[1])' ?

4/8/2019 12:24:33 PM


2 Answers

New Answer


numbers[0] and numbers[1] are both 1 slot in the integer array. Both are of the same size, so it doesn't matter what you choose.


Msizi, Size of integer variable is 4 byte by default. And because of that 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. So output is came out as 100.