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 5 of 7.
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;
}
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?
Mehul said:
1 decade ago
@Apurva Nigam Thanks a lot.
Ravikant said:
1 decade ago
Bitwise operators operate on always nos. Means int, so it converted into int.
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?
Mayuri said:
1 decade ago
Char is 1byte in size. Then why everyone having explanation assuming it is 2 byte ?
Kunal said:
1 decade ago
What is the binary value of x (hexadecimal no) ?
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.
Shanthi said:
1 decade ago
How would you convert binary into decimal (0000 0001 0000 0000=256) ?
Sunil sharma,kaverinagar said:
1 decade ago
What do you mean by 0*80?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers