0
Return
when i try to delete the return result in the example code, it's still give the right answer. So anyone can show me how the 'return' exactly work and when I have to declare return?
10 odpowiedzi
+ 5
@Afif Humaidi
Im sorry, I wasn't able to help much.
+ 3
This is a weird phenomenon. The most probable explanation is that the function is supposed to return an int, and, so, it returned the last int value from the EAX return register.
https://stackoverflow.com/questions/4644860/function-returns-value-without-return-statement
https://stackoverflow.com/questions/4260048/c-function-defined-as-int-but-having-no-return-statement-in-the-body-still-compi
+ 2
Can you post the code? Ill explain using that.
+ 2
this is correct code..
what do u want to do ?
if u want to does not have any return value
use this
#include <iostream>
using namespace std;
void addNumbers(int x, int y) {
int result = x + y;
// return result;
}
int main() {
// cout << addNumbers(50, 25);
}
Notice : of course you can not use cout on void type of function
+ 2
+ 2
thanks guys
+ 1
what is your code?
+ 1
#include <iostream>
using namespace std;
int addNumbers(int x, int y) {
int result = x + y;
return result;
}
int main() {
cout << addNumbers(50, 25);
}
+ 1
No. You help me enough :) @Kinshuk Vasisht
0
there's still result 75