+ 1
Why in first case, value of "i" is 8, but in second case, value is 0? I only made a declaration of variable "i"? Does anyone kno
Case 1: #include <iostream> using namespace std; int main() { int x = 2; int i; // i = 0 cout << i << endl; return 0; } #Output: 8 Case 2: #include <iostream> using namespace std; int main() { int x = 2; int y = 10; int i; // i = 0 cout << i << endl; return 0; } #Output: 0
2 Respostas
+ 4
If you don't initialize a variable he get a random value.
+ 3
Global variables initialized to 0 by default.
Local variables are not initialized. So they will have the garbage value (i. e. Random value), which can not be predicted.