401 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


Deprecated: Implicit conversion from float-string "1632330328.443" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1632330328.443" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1632330328.443" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1632330328.443" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803
435
views
0 answers
0 votes
Shradha Pattanayak asked Apr 15, 2018
435 views
#include <stdio.h>#include "test.h"int main(){i = 10;printf("%d ", i);foo();} in file test1.c#include <stdio.h>#include "test.h"int foo(){printf("%d\n", i);} in file test...
1.2k
views
2 answers
1 votes
Umang Raman asked Oct 7, 2015
1,157 views
int main (){ int a=5,b=3; printf("%d", a+++++b); // 5 +'s }Please Explain.
1.6k
views
3 answers
1 votes
ajit asked Oct 1, 2015
1,603 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...
873
views
1 answers
0 votes
Sarrthak asked Sep 22, 2021
873 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!