Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ Exercise

Name: Anonymous 2008-02-13 11:24

Hi.

I'm attending a C++ programming course. The teacher gave us some exercises, in which we must find what's wrong with the code.
The problem is I'm completly stuck in one of them. I tried to create and compile the following code:
#include<iostream>

using namespace std;

int my_sum(int a, int b)
{
    int c;
    c=a+b;
}

void main()
{
    cout << "2 + 3 = " << my_sum(2,3) << endl;
}


The problem is the compiler gives no errors and the program runs without any errors either.
Could someone PLEASE help me?
Thx in advance.

Name: Anonymous 2008-02-13 12:35

It's a nonstandard thing called "default return", i.e. if you don't return anything the value that was in the register is used, and that register (eax on x86) just happened to contain the result of the last calculation. Don't count on it.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List