78
woops
6y

do it the right way

Comments
  • 9
  • 6
    I can't c shit~ Stevie Wonder
  • 3
    a = 1
    c = c + a
  • 2
    int 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;

    }
  • 1
    @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.
  • 3
    My prefered way:
    c += 1
  • 1
    This one, COUNTS!
  • 1
    I feel happy whenever i have to increment a variable named c, so that i can write c++ in the c++ code ☺️🤣
  • 5
    @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
  • 0
    @hexc i know that already
  • 0
    @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 😐
Add Comment