单选题
有如下程序:
#include<iostream>
using namespace std;
int main()
{
int a=2, b=-1, c=2;
if(a<b)
if(b<0)c=0;
else c+=1;
cout<<c<<endl;
return 0;
}
执行程序的输出结果是______。
【正确答案】
C
【答案解析】[解析] 关键字else总是与它前面最近的未配对的且可见的if配对,而不管书写格式如何。题中的else与if(a<b)中的if配对。由于a>b,故整个if语句未执行,c的值不变。