4

Whats the significance of first argument in an if statement if it's just going to be ignored? For instance, in:

#include<stdio.h>
main()
{
  if(1,0)
    printf("abc");
  else
    printf("qwe");
}
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
jayesh hathila
  • 279
  • 1
  • 6
  • 14
  • 2
    No significance at all. May be the programmer did that to make the if condition false. – UltraInstinct Jun 24 '13 at 12:48
  • This thread gives some explanation on the subject. http://www.cplusplus.com/forum/general/22745/ – Josh Jun 24 '13 at 12:49
  • Also, I believe this is a duplicate of this question. http://stackoverflow.com/questions/1613230/uses-of-c-comma-operator – Josh Jun 24 '13 at 12:49

1 Answers1

9

That's not an argument list, it's the comma operator.

If you have a statement like foo(), bar(), then foo() will be called and its result discarded, then bar() will be called and the entire statement's result will be bar()'s result. Something like if(foo(),bar()) might be used if calling foo() has some side effect that needs to happen for some reason.

For something like 1,0, that is exactly the same as just saying 0 and there is no significance to the 1.

Eric Finn
  • 8,629
  • 3
  • 33
  • 42