Doubt in int getBit()

int getBit(int n, int i)
{
int mask = (1 << i);
return (((n & mask) > 0) ? 1 : 0);
}

What difference will be there if we replace the return statement with return ((n & mask) > 0)? Does it make any difference to the answer?

hello @Rohit39 this is the conditional statement .
it is the syntax of them that after question mark you will write one number which will be stored if the condition is true otherwise the other one will be stored.
Happy Learning !!

But without giving the ? operator and just returning ((n & mask) > 0) ,I am getting the same output. So are both statements correct?

in this you are getting correct answer because in this we are storing 0 and 1 only but what if we have larger numbers to store.
1 and 0 are returning either true or false.
thats why you are getting correct answer.
and yes without ? you have changed the logic that you are just checking but conditional statement also gives you the answer for what if the expression evaluates to be FALSE,.

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.