I used to program in C. And i use to declare struct like in the Code 1. But in C++, i often see struct being declared like in Code 2. My question is, is it bad practice to declare struct in C++ like in Code 1 instead of Code 2.
And btw, i find it that its easier to declare struct in Code 1.
The difference is in the scope of the Objects. Code 1 declares them globally, while Code 2 declares them locally (in main). For this code, it obviously makes no real difference, but in bigger programs you'll want to avoid globally defined variables.