Array of struct size

Hello there!

I try to learn the array of struct and i make one small program. A small part of it is
1
2
3
4
5
	warehouse car[2];
	car[0].inputCar("lamborgini",true);
	car[0].showCar();
	car[1].inputCar("ferrari",true);
	car[1].showCar();


It work peffect but i think that it should be like
1
2
3
4
5
	warehouse car[1];
	car[0].inputCar("lamborgini",true);
	car[0].showCar();
	car[1].inputCar("ferrari",true);
	car[1].showCar();

But if i do it like that i got runtime error:
Stack around the variable 'car' was corrupted.

What do you think ?
warehouse car[2]; means that there are two elements in array: first one is car[0] and the second one is car[1]. warehouse car[1]; is an array with only one element in it, so when you try to access nonexistent second element, debugger gives you an error, since that could harm your whole program.
Nice! Now i see.

Thanks hamsterman for your precious time.
Topic archived. No new replies allowed.