Please somebody explain me the output. | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 5

Please somebody explain me the output.

#include <iostream> using namespace std; int main() { int a[10]; cout<<sizeof(a[1]); cout<<sizeof(a[10]); return 0; } why it shows the size of a[10] as 4 shouldn't it give error as it is out of bound beacause the index is only from 0 to 9?

5th Mar 2017, 2:34 PM
Rishabh Agrawal
Rishabh Agrawal - avatar
4 Antworten
+ 4
@vishnu yes but it is giving me the output. Do give it a try on code playground.
5th Mar 2017, 3:29 PM
Rishabh Agrawal
Rishabh Agrawal - avatar
+ 3
@Mara i am only asking why it is showing the size of a[10] as 4, it should be an error.
5th Mar 2017, 3:28 PM
Rishabh Agrawal
Rishabh Agrawal - avatar
+ 3
@vishnu do you mean like this char a[10] cout<<sizeof(a[10]) in this way or any other?
5th Mar 2017, 6:08 PM
Rishabh Agrawal
Rishabh Agrawal - avatar
+ 1
a[10] doesn't exists... only upto 9 a[0] to a[9]
5th Mar 2017, 3:14 PM
vishnu
vishnu - avatar