393 views
0 votes
0 votes
int c=31, n;
scanf(“%d”,&n);
int k=n<<c;
if(k&&1) return 1;
return 0;

1 Answer

Best answer
2 votes
2 votes

This program is made for 32 bit platform

The output is used to detect whether the input number is odd or even.

As we all know odd number contains 1 as LSB and even number contains 0 as LSB

eg. n = 5 (binary form 101)

     k = 5<<31  //left sift 101 by 31 bit place

     in 32 bit platform, integer can hold only 32 bit of information, therefore it will drop 10 and store 1 at MSB place. 

     (binary form 1000000000000000000000000000000)

     therefore k = -2147483648 (in decimal form) which is non zero.

     hence evaluated as true when evaluating through bitwise And operation and return output as 1.   

selected by

Related questions

0 votes
0 votes
0 answers
1
1 votes
1 votes
2 answers
2
Umang Raman asked Oct 7, 2015
1,160 views
int main (){ int a=5,b=3; printf("%d", a+++++b); // 5 +'s }Please Explain.
1 votes
1 votes
3 answers
3
ajit asked Oct 1, 2015
1,613 views
what is the output of the following c code?#include<stdio.h void main() { int index; for(index=1;index<=5;index++) { printf("%d",index); if(index==3) continue; } }a)1245b...
0 votes
0 votes
1 answer
4
Sarrthak asked Sep 22, 2021
930 views
Hello all, I wanted to know, what is the procedure for getting admission into MS in CSE in IIT Madras. Please also provide the GATE cutoff is possible. Thanks!