0

what does this line do? especially the comma part

ihi = y[0] > y[1] ? (inhi = 1, 0) : (inhi = 0, 1)

25th Jun 2016, 6:28 PM
Garme Kain
Garme Kain - avatar
7 Respostas
+ 2
i understood it. here is what is happening: basically, the syntax is a = (b = 1, 2); what this does is, first, it does whatever is in the parentheses, which is, first assign 1 to b then do another command which is to return 2. after that, the 2 goes to the variable a. so now, a = 2 and b = 1. you could do any expression separated by commas, like: a = (b = 0, b += 2, c = 3, 1); now a = 1, b = 2, c = 3.
25th Jun 2016, 9:35 PM
Garme Kain
Garme Kain - avatar
+ 1
it was in a post of obfuscated c++ code but i want to know this so bad.
25th Jun 2016, 8:05 PM
Garme Kain
Garme Kain - avatar
0
What is inhi here?
25th Jun 2016, 7:47 PM
Aceitunarabe
Aceitunarabe - avatar
0
an int or a bool, i suppose, because you are assigning 0 or 1 to it. but i dont know what does the "," separate. where does the remaining 1 or 0 go?
25th Jun 2016, 7:58 PM
Garme Kain
Garme Kain - avatar
0
OK, hum may be it means a decimal number? Like 0.1 or 1.0?
25th Jun 2016, 8:00 PM
Aceitunarabe
Aceitunarabe - avatar
0
Or may be it's a kind of struct which is composed of two values, like inhi(a, b)
25th Jun 2016, 8:02 PM
Aceitunarabe
Aceitunarabe - avatar
0
there is a , not a . that means it is not decimal. a struct cannot be because the brackets must be { }. thanks for the response though.
25th Jun 2016, 8:04 PM
Garme Kain
Garme Kain - avatar