#include <iostream>
using namespace std;
int func(int);
int main() {
int n = func(2);
cout << n << endl;
return 0;
}
int func(int a) {
int b = a*a;
int c = b*b;
}
Output: 16
Thanks in advance.
This is undefined behavior. You fail to specify the return value.
Anything can happen, including (but not limited to)
returning the last value used.
> DK a écrit :
>> The following program gives the output as the last initialized variable
>> in the function func.
For some platforms and some versions of gcc and some compilation
options:
# Linux/x86
$ g++ -g junk.cc && ./a.out
16
$ g++ -g junk.cc -O && ./a.out
0
# Solaris/SPARC
$ g++ -g junk.cc && ./a.out
16
$ g++ -g junk.cc -O && ./a.out
2
> Anything can happen, including (but not limited to)
> returning the last value used.
And (as above) anything *does* happen ...
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.