0

I tried executing the following c code:

#include <stdio.h>
int main() 
{
int i=2000,j=100; 
printf("%d",(j,i));

}

I gave different values to i and j and found the output. I always get the output as the value contained in the second variable. Does the expression always give the last variable as a result or does it have any other meaning?

Gherbi Hicham
  • 2,416
  • 4
  • 26
  • 41
Gadheyan .t.s
  • 377
  • 2
  • 9
  • 23

1 Answers1

1

You are using the comma operator.

The output of your code is 2000, because the comma operator evaluates the two expressions and returns the value of the second operand. More details can be found in this SO answer.

Community
  • 1
  • 1
abhishek_naik
  • 1,287
  • 2
  • 15
  • 27