Bitwise operations(((())))))

please explain me how the bool function operated…like i didnt get the turnery operator

#include
using namespace std;

bool isodd(int n)
{
int lsb = (n & 1) == 0 ? 0 : 1; // turnery operator
// lsb == 0 // false
// lsb == 1 // non zero value means true
return lsb;
}

int main()
{
int n;
cin >> n;

if (isodd(n) == true)
{
    cout << n << " is odd" << endl;
}
else
{
    cout << n << " is even" << endl;
}

return 0;

}

@abhinavssr2003_eab0717682969e5c

condition ? expression1 : expression2;

Ternary operator works like, if the condition is true statement 1 is executed else statement 2 is executed. So in the program , lets say the no is even its bitwise and with 1 will always be 0 (as even no end with a zero in binary form) so 0 == 0 ? yes … so will return 0

@abhinavssr2003_eab0717682969e5c,
its function to check odd or even if (n&1) is 0 then its even so its returning 0 else if odd then returning 1

read more here : https://www.geeksforgeeks.org/conditional-or-ternary-operator-in-c-c/

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.