retagged by
1,863 views
0 votes
0 votes
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;
}
    A.    12400
    B.    12480
    C.    12500
    D.    12556
retagged by

2 Answers

Best answer
5 votes
5 votes
When %c is given in printf, the character corresponding to the 8 bit value being passed is printed. Unless otherwise stated, we can assume ASCII characters being used.

char c=48 takes the ASCII value of 48 which is '0';

c=48 binary number 00110000

mask 00000001

c|mask(unary OR operator, use binary value and then OR operation)=00110000+00000001=00110001=49

Now 49 is equal to ASCII value 1, 50 is ASCII value 2 etc.

So, it will print 12480
edited by

Related questions

0 votes
0 votes
1 answer
1
rishu_darkshadow asked Nov 8, 2017
332 views
In C language, bitwise operation can be applied to which of the following operandsA. char B. int C. short, long ...
3 votes
3 votes
1 answer
2
dd asked Jun 27, 2017
522 views
#include <stdio.h int main() { unsigned int m = 0; m |= 0xA38; printf("%x\n",m|(m-1)); printf("%x\n",( (m|(m-1)) + 1 ) & m ); }Find the output ?
0 votes
0 votes
1 answer
3
dd asked Apr 20, 2017
718 views
int main() { int n = 3,i,count=0; for(i=0;i<1<<n;i++) { int p = i; while(p) { int k = p & -p; p = p - k; count++; } } }The value of count variable after execution of the ...