Hello. I was wondering what the value of a declared but undefined variable would be. I assumed 0, so i tested. Then things got wierd.
with this code:
#include <iostream>
int main()
{
std::cout << "Hello secret agent. Good luck breaking into the server.";
std::cout << std::endl;
std::cout << "Enter the correct code on your first try, or the bomb will detonate.";
const int a = 4;
const int b = 7;
const int c = 3;
int x;
std::cout << x << std::endl;
const int sum = a+b+c;
const int product = a*b*c;
std::cout << std::endl;
std::cout << sum << std::endl;
std::cout << product << std::endl << std::endl;
std::cout << "haha";
return 0;
}
Returns this:
Hello secret agent. Good luck breaking into the server.
Enter the correct code on your first try, or the bomb will detonate.6165043
14
84
haha
Why is x not zero?
But when i make a positional change as follows:
#include <iostream>
int main()
{
std::cout << "Hello secret agent. Good luck breaking into the server.";
std::cout << std::endl;
std::cout << "Enter the correct code on your first try, or the bomb will detonate.";
const int a = 4;
const int b = 7;
const int c = 3;
const int sum = a+b+c;
const int product = a*b*c;
int x;
std::cout << x << std::endl;
std::cout << std::endl;
std::cout << sum << std::endl;
std::cout << product << std::endl << std::endl;
std::cout << "haha";
return 0;
}
It properly return zero, as seen in:
Hello secret agent. Good luck breaking into the server.
Enter the correct code on your first try, or the bomb will detonate.0
14
84
haha
I am baffled.