下面的代码打印:
5
为什么要打印 5?此外,如果它返回 5,为什么它不打印“James”?我不明白下面的代码。如果我删除 else 字,它会打印 -1。但是它不应该返回一个默认值吗?
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int fonk()
{
int a = 5, b = 3;
int c = a*b;
if(c >10)
{
if( a<b && a >0)
{ cout <<"James";
return a;
}
else if(b<0)
{
return b;
}
}
else return -1;
}
int main()
{
int x = fonk();
cout << x;
}