简体   繁体   English

一行中有多个运算符

[英]Multiple operators in one line

vector<int> G[MAXN] ;

char isLeaf[MAXN] ;

int n,path;

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

// How the code in For loop works? // For循环中的代码如何工作? I am confused of multiple operators here. 我对这里的多个运算符感到困惑。

Due to operator precedence and associativity , the statement 由于运算符的优先级和关联性 ,该语句

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

is equivalent to: 等效于:

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

If you divide it into multiple statements for clarity, you get: 如果为了清楚起见将其分成多个语句,则会得到:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM