Comma value in number

Possible duplicate:
C ++ Comma Operator

which is probably a trivial question, but I don’t know the answer. And it bothered me this afternoon.

I just wrote a function to convert RVB to YUV. Nothing special, but mistakenly used a comma (,) instead of a period in my numbers.

It compiles, but the result was not what I expected, for example, "-3713796" instead of the range number 0-255.

(0,615*(double) 61) - (0,51498*(double) 61) - (0,10001*(double) 61) 

So what does that mean?
If this is not a compilation error, it is probably useful for something, but what?

Ps: I used C ++ with Qt.

+4
source share
2 answers

You accidentally used a comma operator. It evaluates its first operand and discards the result, and then evaluates the second operand and returns its value and type.

In my experience, it is most often used in loop statements. For other purposes, see Using C-comma c

+7
source

This is a comma operator that evaluates each operand and returns the rightmost one. In this case, he rated 0, then 615*(double) 61 and led to the value of this product.

+1
source

Source: https://habr.com/ru/post/1390654/


All Articles