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
-
catadoxa4166yint addOne(int x)
{
int m = 1;
// Flip all the set bits
// until we find a 0
while( x & m )
{
x = x ^ m;
m <<= 1;
}
// flip the rightmost 0 bit
x = x ^ m;
return x;
} -
hexc11266y@nobes depends on the use case, ++n and n++ are not the same. The first adds one before being evaluated inline where as the later adds one after evaluation. So if you were trying to make a loop using the %(mod) operator for instance, a = ++a % max would work as expected but a = a++ % max wouldn't.
-
ceee77796yI feel happy whenever i have to increment a variable named c, so that i can write c++ in the c++ code ☺️🤣
-
@catadoxa
switch (c) {
case 1:
c = 2
break;
case 2:
c = 3
break;
case 3:
c = 4
break;
case 4:
c = 5
break;
case 5:
c = 6
break;
...
}
With this we can do O(1) increment! I’ll submit my research papers soon -
@growling c is not defined or null before you add a to it... so it would probably be a concat. of null and a... that's not good 😐
do it the right way
joke/meme