I know that arrays need to be defined with a size that cannot be modified, but in this code, the counter i exceeds the size of the array (because of the 2 in "i<sz+2" in the for loop) but the code don't give any errors, why? another question: is it correct to use std::cin to assign the value to sz or should I assign the value of sz when I declare the variable?
#include <iostream>
int main() {
int sz;
std::cin >> sz;
int v[sz];
std::cout << "i" << " " << "v[i]" << std::endl;
for(int i=0;i<sz+2;i++){
std::cin >> v[i];
std::cout << i << " " << v[i] << std::endl;
}
return 0;
}