#include<stdio.h>
int sel=5,out=10;
int findout(){
if(sel==5)
return out*=2;
}
int main(){
int ret1,ret2=-1;
ret1=findout();
printf("before %d %d %d",sel,out,ret1);
sel=8;out=7;
ret2=findout();
printf("\nafter %d %d %d",sel,out,ret2);
}
Output:
before 5 20 20
after 8 7 8
EDIT: My compiler doesn't show any warnings.Here you can see it. Its on codeblocks GNU GCC compiler on Ubuntu OS
g++ -c Untitled1.cpp -o Untitled1.o
g++ -o Untitled1 Untitled1.o
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))
Here in second case,when I did not return any value (for sel=8
and out =7
) how come the value of ret2
is 8
?
When sel
is not 5
your function findout()
does not go through a return
statement.
That is illegal C; and your compiler should warn you about it.
Do not ignore your compiler warnings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With