Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

a pair of number enclosed in parentheses

Tags:

c++

Here is a block of code. Can anyone explain what it means to have a pair of numbers enclosed inside 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";
like image 940
Shawn Avatar asked Dec 20 '22 14:12

Shawn


1 Answers

That's the comma operator; it evaluates the thing on the left, throws the result out, and returns the result on the right. Since evaluating an int variable has no side-effects, that if is semantically equivalent to

if(b < d)
like image 88
nneonneo Avatar answered Dec 24 '22 00:12

nneonneo