Prerequisite: Shift operators
Q.1 What Is The Output Of this program?
ans :- b
Explanation :- We know that 0x is hexa-decimal representation of number so 80 converted in decimal is 128 binary(10000000), its left shift 1 so it is (100000000)equal to 256.
Q.2 What Is The Output Of this program?
a) 65535 -65536
b) -65535 65535
c) 65535 65535
d) -65535 -65535
ans :- a
Explanation :- This code 0x is Hexadecimal representation of number so ffff hexadecimal is converted into Decimal 65535 and stored in a. The negation of a -65535 is stored in k. k is an unsigned integer but it has a negative value in it. When k is being printed the format specifier is %d which represents signed integer thus -65536 gets printed as value of k. If the format specifier for k had been %u the value that would have been printed is 4294901760.
Q.3 What Is The Output Of this program?
ans :- d
Explanation :- Here a integer is simply left-shifted 4 bit and print so it is -16.
Q.4 What Is The Output Of this program?
a) 16 5
b) 64 -32
c) 16 33
d) 16 -33
ans :- d
Explanation :- This program 32 is(10000) and we know that negative number in binary system contain a one’s complement so here take a complement of a number and only print this number so the negation of 32 is -33.
Q.5 What Is The Output Of this program?
a) -2, 7
b) 2, 8
c) -1, 15
d) -2, 15
ans :- a
Explanation :- Here -1 binary(0001) if left shift 1 so it is -2(0010) and 15 binary(1111) is right shift 1 so it is (0111)so value 7.
This article is contributed by Gyayak jain . If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.