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.

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.

Adi said:   1 decade ago
Razia, its not printing mask.

Its printing 49 as 49-48=1
then 50-48=2
then 52-48=4 and
then 48-48=0 on it prints 12480.

Yamini said:   1 decade ago
I cant understand that left shift operation "<<"
Can anyone pls explain me n make me clear

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

Priyanka said:   1 decade ago
For last loop.
i=5;

0011 0000
|0001 0000
=0100 0000 its 64.

how come its 48?

Tanu Priya Saxena said:   1 decade ago
Mask is declared 01. It should be read as an octal since it is starting with 0.

Razia said:   1 decade ago
It is supposed to print c|mask, instead it is printing only the value of mask.

Pritam said:   1 decade ago
At 5th loop mask=01000 and 48 or 01000 gives 64 then how it comes 48 again?

K.Harika said:   1 decade ago
Please give the correct answer properly.I can't understand this program.

Jitendra Malviya said:   1 decade ago
Mask is assigned 1 i.e. 00000001, means? I am not getting point.


Post your comments here:

Your comments will be displayed after verification.