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;
}
Discussion:
65 comments Page 6 of 7.
ULLAS K said:
1 decade ago
@nikita.
Bitwise operator can't be applied to float and double type. This its limitation,
Check out in books.
Bitwise operator can't be applied to float and double type. This its limitation,
Check out in books.
Kunal said:
1 decade ago
What is the binary value of x (hexadecimal no) ?
Mayuri said:
1 decade ago
Char is 1byte in size. Then why everyone having explanation assuming it is 2 byte ?
Sushma said:
1 decade ago
I've the same doubt..:(
char is 1 byte
so, 0x80= 1000 0000
i<<1 = 0000 0000 rite?
Is it dat %d in the printf statement matters?
char is 1 byte
so, 0x80= 1000 0000
i<<1 = 0000 0000 rite?
Is it dat %d in the printf statement matters?
Ravikant said:
1 decade ago
Bitwise operators operate on always nos. Means int, so it converted into int.
Mehul said:
1 decade ago
@Apurva Nigam Thanks a lot.
Sutendra mirajkar said:
1 decade ago
#include<stdio.h>
int main()
{
unsigned char i = 0x80;
i=i<<1;
printf("%d %d %d\n", i);
return 0;
}
Then the output of i is zero can anyone explain why is it so?
int main()
{
unsigned char i = 0x80;
i=i<<1;
printf("%d %d %d\n", i);
return 0;
}
Then the output of i is zero can anyone explain why is it so?
Chotu said:
1 decade ago
Dear sutendra Mirajkar
int main()
{
unsigned char i = 0x80;
i=i<<1;// i is char so 0.
0x80 in binary 1000 0000
after letf shift(i<<1) is 0000 0000 .That value store in i char(1byte 00000000)
printf("%d\n", i);// out put is 0
return 0;
}
//////////////////////////////////////
our result in inter thats y i take int var; i<<1 value is store int var. The output is 256
int main()
{
unsigned char i = 0x80;
int var;
var=i<<1;
printf("%d %d %d\n", var);
return 0;
}
int main()
{
unsigned char i = 0x80;
i=i<<1;// i is char so 0.
0x80 in binary 1000 0000
after letf shift(i<<1) is 0000 0000 .That value store in i char(1byte 00000000)
printf("%d\n", i);// out put is 0
return 0;
}
//////////////////////////////////////
our result in inter thats y i take int var; i<<1 value is store int var. The output is 256
int main()
{
unsigned char i = 0x80;
int var;
var=i<<1;
printf("%d %d %d\n", var);
return 0;
}
Sumit said:
1 decade ago
Nikita its not << operator , which converts char to int , its %d which makes changes with c , try to use %c it will give blank as , Ascii value of NULL is 0
Spa said:
1 decade ago
Why everyone taking for char 2bytes. ? can any one explain me.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers