0

In this comma-separated expression. Why doesn't the x gets value an instead of b?

int main() {

int a=20;
int b=100;
int x;
x=(a,b);

cout<<x;
}

Gives output: 100

Yakk - Adam Nevraumont
  • 262,606
  • 27
  • 330
  • 524
Naval Kishore
  • 115
  • 1
  • 7

1 Answers1

1

The comma operator evaluates the left hand side, discards it, evaluates the right hand side, returns it.

Yakk - Adam Nevraumont
  • 262,606
  • 27
  • 330
  • 524