Exercise: Bitwise Operators

Questions for: Bitwise Operators

What will be the output of the program?
#include<stdio.h>

int main()
{
    unsigned int res;
    res = (64 >>(2+1-2)) & (~(1<<2));
    printf("%d\n", res);
    return 0;
}
A:
32
B:
64
C:
0
D:
128
Answer: A
No answer description is available. Let's discuss.
What will be the output of the program?
#include<stdio.h>

int main()
{
    printf("%d %d\n", 32<<1, 32<<0);
    printf("%d %d\n", 32<<-1, 32<<-0);
    printf("%d %d\n", 32>>1, 32>>0);
    printf("%d %d\n", 32>>-1, 32>>-0);
    return 0;
}
A:
Garbage values
B:
64 32
0 32
16 32
0 32
C:
All zeros
D:
8 0
0 0
32 0
0 16
Answer: B
No answer description is available. Let's discuss.
What will be the output of the program ?
#include<stdio.h>

int main()
{
    int i=32, j=0x20, k, l, m;
    k=i|j;
    l=i&j;
    m=k^l;
    printf("%d, %d, %d, %d, %d\n", i, j, k, l, m);
    return 0;
}
A:
0, 0, 0, 0, 0
B:
0, 32, 32, 32, 32
C:
32, 32, 32, 32, 0
D:
32, 32, 32, 32, 32
Answer: C
No answer description is available. Let's discuss.
What will be the output of the program?
#define P printf("%d\n", -1^~0);
#define M(P) int main()\
             {\
                P\
                return 0;\
             }
M(P)
A:
1
B:
0
C:
-1
D:
2
Answer: B
No answer description is available. Let's discuss.
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
Answer: B
No answer description is available. Let's discuss.
Ad Slot (Above Pagination)
Quiz