一行中有多个运算符

时间:2016-10-27 19:00:43

标签: c++ algorithm operators

vector<int> G[MAXN] ;

char isLeaf[MAXN] ;

int n,path;

for(int i = 0;i < n;i++) path -= isLeaf[i] = G[i].size() == 1 ;

// For循环中的代码如何工作?我对这里的多个运营商感到困惑。

1 个答案:

答案 0 :(得分:2)

由于operator precedence and associativity,声明

path -= isLeaf[i] = G[i].size() == 1 ;

相当于:

path -= (isLeaf[i] = (G[i].size() == 1));

如果为了清楚起见将它分成多个语句,你会得到:

bool temp = (G[i].size() == 1);
isLeaf[i] = temp;
path -= isLeaf[i];