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 3 of 7.

Rohit said:   1 decade ago
@Sai. Thank you very nuch.

Ravi said:   1 decade ago
Thanks sai.

Mun said:   1 decade ago
Left shift << is Multiply by power of 2.
So therefore ,12480 consecutively 5 times !!

Ajit Yadav said:   1 decade ago
For those having problem in 5th loop.
C = 48 = 110000.
Mask= 16 = 010000.
Perform or operation and you will get 110000 i.e. 48.
And 48 in ascii is '0'.

Bhavesh said:   1 decade ago
"c|mask" what does it mean?

Amey said:   1 decade ago
c=110000
Mask=000001
In for loop
i=1
Print 110000 | 000001 i.e. 110001=49 i.e. ascii for '1'
Hence printing '1'
Now mask<<1 hence mask=000010
i=2
Print 110000 | 000010 i.e. 110010=50 i.e. ascii for '2'
Hence printing '2'
Now mask<<1 hence mask=000100
i=3
Print 110000 | 000100 i.e. 110100=52 i.e. ascii for '4'
Hence printing '4'
Now mask<<1 hence mask=001000
i=4
Print 110000 | 001000 i.e. 111000=56 i.e. ascii for '8'
Hence printing '8'
Now mask<<1 hence mask=010000
i=5
Print 110000 | 010000 i.e. 110000=48 i.e. ascii for '0'
Hence printing '0'
Now mask<<1 hence mask=001000

Pramod Soni said:   1 decade ago
Thank you very much Amey.

Vraj shah said:   1 decade ago
Thanks amey :).

Ruella said:   1 decade ago
Amey that was impressive and neat! thanks

Gayatree verma said:   1 decade ago
Thanks amey and sai.


Post your comments here:

Your comments will be displayed after verification.