I have the following C++ code:
#include <iostream>
using namespace std;
#include <stdio.h>
int main (int argc , char ** argv)
{
int i1;
int i2;
double d1;
double d2;
printf("i1: %d, i2: %d, d1: %f, d2: %f \n", i1, i2, d1, d2);
}
The output is
i1: 4195872, i2: 0, d1: 0.000000, d2: 0.000000
Everytime I run the programme I'm getting the same output. Now let's say I'm using the following code:
#include <iostream>
using namespace std;
#include <stdio.h>
int main (int argc , char ** argv)
{
int i1;
int i2;
double d1;
double d2;
cout << "i1: " << i1;
cout << " i2: " << i2;
cout << " d1: " << d1;
cout << " d2: " << d2;
}
Now I'm getting the following output:
i1: 4196144 i2: 0 d1: 6.95294e-310 d2: 0
The value for d1 changes slightly when I rerun the programme, the other values stay the same.
Why are the values initialized this way? Why is there no random initialization or initialization to zero?