Mar 26, 2011 at 7:44pm UTC
I understand that
#include <iostream>
int main ()
{
bla
bla
bla
}
Is a function. It has x amount of statements.
Then when you return values suddenly, cout << Return5(); // prints 5
becomes a function as well.
Mar 26, 2011 at 7:55pm UTC
that's right... you have a method int Return5() {} when you call this method the calling is replaced by the return value. what's the problem?
regards
Mar 26, 2011 at 8:10pm UTC
It's more that I am confused as to the terminology.
cout << Return5();
should produce out-put from
Return5 () {}
if i am correct.
that is a function.
the activity below it asks me to use these various functions in a program.
cout << Return5();
cout << Return5() + 2; // prints 7
cout << ReturnNothing(); // This will not compile.
How are they functions, i thought they were statements. (x amount of statements makes a function)
unless -.-
cout << Return5();
its saying print the value of function Return5 ()???
Thank you
Regards.
Last edited on Mar 26, 2011 at 8:10pm UTC
Mar 26, 2011 at 10:16pm UTC
Try this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
using namespace std;
int Return5()
{
return 5;
}
void ReturnNothing()
{
return ;
}
int main ()
{
cout << Return5(); // this calls the function and prints it's return value
cout << Return5() + 2; // same as above, but adds 2 to it's return value
cout << ReturnNothing(); // same as above, but nothing is returned from function (void)
}
See
http://www.cplusplus.com/doc/tutorial/functions/ for more info.
Last edited on Mar 26, 2011 at 10:22pm UTC
Mar 27, 2011 at 1:20am UTC
// this calls the function and prints it's return value
its!
Mar 27, 2011 at 2:45am UTC
teddyeddy wrote:
cout << ReturnNothing(); // This will not compile.
He already mentioned that before.
Last edited on Mar 27, 2011 at 2:46am UTC