Question 1: My friend asked me a question, and I wanted to verify that my understanding was correct. If I declare an array of a certain size, but do not specify the value of each element, then print it out, I get all 0s. But that is the compiler that is making them 0s correct? All I can expect from declaring an array of X size, is that it will allocate a contiguous block of that size correct? I should not count on them always being zero, and should manually initialize them myself.
Question 2: I have read on a message board that newer c++ lets you declare an array that has a user defined size. That does not make sense to me, I've always thought it needed to be known at compile time. What's the deal here? Is this syntactic sugar? Whats going on under the hood?
#include <iostream>
using namespace std;
void question2()
{
int userInput;
cin >> userInput;
int anotherArray[userInput];
}
int main()
{
int array[5];
for (int i = 0; i < 5; i++) {
cout << array[i] << endl;
}
cout << endl;
question2();
}
I would expect jibberish output from main and an error saying something like, "userInput not const" but I am getting 0 0 0 0 0 and user input, and Process exited after 2.857 seconds with return value 0