0

Can someone explane why sizeof(n[2])=4?

//Note:assume int is 4 bytes int main() { //sizeof(n)=200 int n[50]; //sizeof(n[2])=4 cout<<sizeof(n)/sizeof(n[2]); } //Output: 50

5th May 2019, 7:23 PM
San Anemos
San Anemos - avatar
2 Answers
+ 6
If you're asking why `sizeof(n[2])` yields 4 then it is because <n> is an array of int, so each element in array <n> itself is an int, which is (commonly) 4 bytes in memory allocation size. If I misunderstood your question then explain your intention more clearly : )
5th May 2019, 7:34 PM
Ipang
+ 2
n[2] is only one integer, so n[2] = 4 bytes
5th May 2019, 7:31 PM
Pikachu
Pikachu - avatar