Visual Studios and even Codechef is compiling my code which has a missing return statement.
I was solving some competitive programming question and noticed that my program is compiled without a return statement in a function. I wrote a simple function and didn't mention any return statement and the program is being compiled perfectly.
Here's the code
#include <iostream>
using namespace std;
int add(int x, int y)
{
int c = x + y;
}
int main() {
int a = add(1, 2);
cout << a;
return 0;
}
I was expecting an error which I didn't get and made me wonder what was wrong with my code(of-course not the above one). And in the program above I'm getting output 0
which I don't understand how?