1

I accidentally typed while(x,0) instead of while(x<0). The code of course didn't work as planned nor got compiler errors so i took a damn hour to find the mistake.

Why it didn't get a compiler error? And what does the , do in the while loop?

Arjun Mathew Dan
  • 5,125
  • 1
  • 15
  • 27

2 Answers2

1
while(x,0)

comma is treated as binary operator and it will return 0, so your loop condition will go false.

Pras
  • 4,012
  • 9
  • 20
1

In C, a comma is "a binary operator that evaluates its first operand and discards the result, and then evaluates the second operand and returns this value (and type)."

Since 0 is false then your code was exiting the loop.

https://en.m.wikipedia.org/wiki/Comma_operator

Chris Sharp
  • 1,947
  • 18
  • 30