A pair of numbers enclosed in parentheses

Here is the code block. Can anyone explain what it means to have a pair of numbers enclosed in parentheses. (This is in C ++.)

int a = 2, b = 2, c = 3, d = 1; if((a,b)<(c,d)) cout<<"case1"<<endl; else cout<<"case2"; 
+4
source share
2 answers

This is a comma operator; he evaluates the thing on the left, gives the result and returns the result on the right. Since evaluating an int variable has no side effects, if semantically equivalent

 if(b < d) 
+13
source

Or, if the value changes or is accepted as user input, you can use && (s), || (or) logical operators for sorting your codes

if ((a<c) && (b<d))

or

if ((a<c) || (b<d))

That way you can do things the way you like. Check here the operators http://www.cplusplus.com/doc/tutorial/operators/

-2
source

Source: https://habr.com/ru/post/1441173/


All Articles