性质
如果&&前面的部分不满足条件,则&&不会执行后面的部分,因此可以做些有趣的事。
应用
充当if语句
#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
using namespace std;
int func(int n) {
int res = n;
n> 0 && (res= func(n - 1) + n);
return res;
}
int main()
{
int n, m;
cin >> n;
m = func(n);
cout << m;
}