C Programming - Bitwise Operators - Discussion

Discussion Forum : Bitwise Operators - Find Output of Program (Q.No. 5)
5.
What will be the output of the program?
#include<stdio.h>

int main()
{
    unsigned char i = 0x80;
    printf("%d\n", i<<1);
    return 0;
}
0
256
100
80
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
65 comments Page 7 of 7.

Chandini said:   1 decade ago
Please explain briefly about this program.

Kuljeet said:   1 decade ago
@Spa- because its an unsigned char value. its range is 0 to 255. hence it can take any value between 0 and 255, which in this case is 80, represented in hexadecimal form.

ANJANI said:   1 decade ago
Thanks a lot. For your nice explanation. I m fully overwhelm.

Mayur said:   1 decade ago
int main()
{
unsigned char i = 0x80;
printf("%d\n", i<<1);
return 0;
}
i=0x80 means 0000 1000 0000
After <<(1 bit shift left) It will become
0001 0000 0000 that means 256.

Vinay said:   1 decade ago
i = 0x80 it is in hexadecimal form.
Decimal form of i =8*16^1+0*16^0=128= 00000000 10000000 in binary form.

After i<<1 it becomes 00000001 00000000. Its decimal equivallent is 256.


Post your comments here:

Your comments will be displayed after verification.