+ 2
Can anybody explane me?
Int a=0,b=0; While(a<7,b<17) A++; B++; Printf("%d%d",a,b);
3 Réponses
+ 5
int a = 0,
b = 0;
// while ( (evaluted, then discarded) , (evaluated, then returned))
while ( a<7, b<17 ) { // comma operator ¹
a++;
b++;
printf("%d %d\n", a, b);
}
Output:
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
11 11
12 12
13 13
14 14
15 15
16 16
17 17
_____
¹ The comma operator expression has the form
lhs , rhs
where
lhs - any expression
rhs - any expression other than another comma operator (in other words, comma operator's associativity is left-to-right)
First, the left operand, lhs, is evaluated and its result value is discarded.
Then, a sequence point takes place, so that all side effects of lhs are complete.
Then, the right operand, rhs, is evaluated and its result is returned by the comma operator as a non-lvalue.
https://en.cppreference.com/w/c/language/operator_other#Comma_operator
+ 2
Thank you all
+ 1
It is a code of implementation.
So when a and b will take a number who overtake 7, it will be added 1 to a and b