Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@spl0 you can do assingnments in a condition.
if(a = 1) is the equivalent of:
a = 1;
if(a)
Not that it's very useful in this case :) -
Andlat148y@freakbyte isn't instead if the assignement was successful? In c++, the assignement operator usually returns a reference to the "assigned to" variable, which is then evaluated. Don't know if c is the same...
-
Andlat148y@spl0 In c++, the assignement operator = usually returns a reference if it was successful. So a = 1 returns &a and that is what is evaluated in the condition. I learned that from c++ primer and have been using it like this for years, but I might have misunderstood. I'll do some tests later.
-
Andlat148y@spl0 your code prints the value of ++a. Here's a link on a stackoverflow question explaining the return value: http://stackoverflow.com/questions/...
= and ==
Or
:= and =
?
undefined
best assignment and comparison