Added a 'Note' part. (#32776)
The 'Note' part describes how we can check for odd even with the help of & operator.
This commit is contained in:
committed by
Randell Dawson
parent
447b8f50fc
commit
b07fac01b2
@ -254,6 +254,27 @@ evaluated first.
|
||||
- Assignment `= += -= *= /= %= >>= <<= &= ^= |=`
|
||||
- Comma `,`
|
||||
|
||||
## Note:
|
||||
We can use & operator for checking whether a given number is even or odd more quickly than regular way.
|
||||
### Example
|
||||
```C
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int a=25;
|
||||
if(a&1)
|
||||
printf("Odd");
|
||||
else
|
||||
printf("Even");
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
## Output
|
||||
```
|
||||
-> Odd
|
||||
```
|
||||
The value of (a & 1) will be a non zero element only when a is odd, and 0 if it is even.
|
||||
|
||||
## 7. Conditional Operators
|
||||
|
||||
## Syntax
|
||||
|
Reference in New Issue
Block a user