Search:

Type: Posts; User: Polymorphic OOP

Search: Search took 0.02 seconds.

  1. Sticky: Because you are "cout"ing the value that evenTest...

    Because you are "cout"ing the value that evenTest returns (which is garbage cuz you didn't return anything.

    What you should do is:


    /* a function that tests whether an integer is even,...
  2. Sticky: It's result is 1 if it's odd and 0 if it's even ...

    It's result is 1 if it's odd and 0 if it's even

    so



    std::cout << "Value is " << ( Value & 1 ? "odd" : "even" );
  3. Sticky: Bitwise operations are faster than division,...

    Bitwise operations are faster than division, multiplication, addition, subtraction because it's just a quick check on the bits.
  4. Sticky: Or, if you want to optimize just do: Value & 1...

    Or, if you want to optimize just do:

    Value & 1

    if the result of the expression is true then the number was odd, if false, then the number was even
Results 1 to 4 of 4