Hey, on Friday I have a c++ test and as a preparation we have been given an old test to practice on, one of the questions are: What does this program output. I though it would be:
0
1
2
3
4
However the output when I try it is:
4273030
4272928
9385600
92
Why is that?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
usingnamespace std;2686760
int main(){
int tal[5];
int i;
for(i=0; i<5; i++)
{
cout << tal[i] << " "; //____________0 1 2 3 4
cout <<endl;}
return 0;
}
Basically int tal[5]; just grabs some memory for that array. It does not change what is in that memory, so you get "random" numbers. Restart your computer and those numbers will be different. (there are other ways to get them to change like loading another program, and then loading this program.)