Originally Posted by
loserone+_+
really that i can return one thing only?
Yes. The comma operator does not change return semantics. What will happen instead is that the left expression will be evaluated followed by the right.
Code:
#include <stdio.h>
int x = 1;
int foobar(void) {
int y = 0;
return x *= 4, y;
}
int main(void) {
int rv;
printf("x before foobar() = %d\n", x);
rv = foobar();
printf("foobar() returned = %d\n", rv);
printf("x after foobar() = %d\n", x);
return 0;
}
As in this program. As the author may have intended to return both the new value of x and 0, it doesn't really work, and in any case, the main() function was not prepared to receive 2 things. Instead, the new value of x is a side effect of invoking foobar(). Which is bad because you want functions to have clear expectations of input and output.
If you pack variables into a structure, you can return as many values as you want, but you are still returning a single object.
hmmm, i already change that and compile again
still had errors
Some logical errors, like this one, cannot be stopped by the compiler as well.