I have this code:
#include <iostream>
using namespace std;
void funcA()
{
int a = 4;
}
void funcB()
{
int b;
cout << b;
}
int main()
{
funcA();
funcB();
cout << endl;
return 0;
}
If I compile it without optimization: g++ -o run file.cpp
I am receiving as result : 4
If I compile it with : g++ -O3 -o run file.cpp
I am receiving as result : 0
Now, I would expect in both cases
1) Return nothing from funcA since we are just calling it and in funcA we are just assigning a value to a variable ( don't return anything ).
2) Return a warning from compiler regarding funcB since we are not initializing b value.
I found this answer better (more detail).