C Programming - Bitwise Operators - Discussion
Discussion Forum : Bitwise Operators - Find Output of Program (Q.No. 7)
7.
What will be the output of the program?
#include<stdio.h>
int main()
{
char c=48;
int i, mask=01;
for(i=1; i<=5; i++)
{
printf("%c", c|mask);
mask = mask<<1;
}
return 0;
}
Discussion:
70 comments Page 3 of 7.
Jitendra vaishnav said:
9 years ago
@Mukunda Saini.
OR operation doesn't means sum its logical or operation.
Where 1 OR 1 is 1. So there will be no carry on next position.
OR operation doesn't means sum its logical or operation.
Where 1 OR 1 is 1. So there will be no carry on next position.
Vasundhara said:
9 years ago
Thanks, easy explanations @Amey.
Shravan said:
9 years ago
@Sai.
Very good explanation. Thank you.
Very good explanation. Thank you.
Hamilton said:
8 years ago
Thanks for all your explanation.
Merlin said:
8 years ago
Good Explanation, thanks @Amey.
Komal said:
8 years ago
Very nice, Thank you all.
Dinesh said:
8 years ago
Can we assign an integer value in char data type?
Maheswari said:
8 years ago
Yes, you can assigned integer value in char data type.
For example :
char i=21;
printf("%c",i); //it will not print anything and no error;
printf("%d",i);//it will print the value of I;
For example :
char i=21;
printf("%c",i); //it will not print anything and no error;
printf("%d",i);//it will print the value of I;
Jayesh said:
8 years ago
Thanks, nice explanation @Amey.
Santhosh kumar said:
8 years ago
@Priyanka.
"or" operation performed is not like 1+0=0, 1+1=0, 0+0=0
it is performed using truth table like;
OR truth table
Input Output
1 - 1 1
1 - 0 1
0 - 1 1
0 - 0 0
therefore
the operation on
0011 0000
0001 0000
_________
0011 0000
________
which is equal to 48 whose ascii value is 0.
what you have done is
11
0011 0000
0001 0000
________
0100 0000
_________
So or operation is done using truth table conditions.
"or" operation performed is not like 1+0=0, 1+1=0, 0+0=0
it is performed using truth table like;
OR truth table
Input Output
1 - 1 1
1 - 0 1
0 - 1 1
0 - 0 0
therefore
the operation on
0011 0000
0001 0000
_________
0011 0000
________
which is equal to 48 whose ascii value is 0.
what you have done is
11
0011 0000
0001 0000
________
0100 0000
_________
So or operation is done using truth table conditions.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers