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;
}
12400
12480
12500
12556
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
70 comments Page 1 of 7.

Srujana said:   4 years ago
Thanks all for explaining.
(2)

AVJagjeet said:   5 years ago
@Sai.

As per my knowledge, the explanation is.

itr 1 0001 | 110000 => 49 => ifsc printing %c so convert int to char by ifsc i.e. 1.

itr 2 0010 | 110000 => 50 => ifsc printing %c so convert int to char by ifsc i.e. 2.

itr 3 0100 | 110000 => 110100 => 52 => ifsc printing %c so convert int to char by ifsc i.e. 4.

itr 4 00001000 | 110000 => 111000 => 56 => ifsc printing %c so convert int to char by ifsc i.e. 8.

itr 5 00010000 | 110000 => 110000 => 48 => ifsc printing %c so convert int to char by ifsc i.e. 0.
(12)

Varsha said:   5 years ago
Thanks @Sai, @Jayadeep and @Amey.
(1)

Dhivya said:   6 years ago
How to find ascii value manually?

Please explain.

Padma said:   6 years ago
Thank You @Sai.

Ruhee said:   7 years ago
Thanks @Jayadeep.

Neha said:   7 years ago
Thanks @Amey.

Zhongshunchao said:   7 years ago
0011 0000 == 48 ---0
0011 0001 == 49 ---1 48|0001.
0011 0010 == 50 ---2 48|0010.
0011 0100 == 52 ---4 48|0100.
0011 1000 == 56 ---8 48|1000.
0011 0000 == 48 ---0 48|0000.

Zhongshunchao said:   7 years ago
0011 0000 == 48 ---0.
0011 0001 == 49 ---1.
0011 0010 == 50 ---2.
0011 0100 == 52 ---4.
0011 1000 == 56 ---8.
0011 0000 == 48 ---0.

Santhosh kumar said:   7 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.


Post your comments here:

Your comments will be displayed after verification.