• edited by
4,913 views
3 3 votes

What will be the output of the program ?

#include<stdio.h>

int main()
{
    int i=4, j=8;
    printf("%d, %d, %d\n", i|j&j|i, i|j&j|i, i^j);
    return 0;
}




    A.    12, 12, 12
    B.    112, 1, 12
    C.    32, 1, 12
    D.    -64, 1, 12

2 Answers

Best answer
4 4 votes

Your Answer needs operator precedence table of C given http://www.difranco.net/compsci/C_Operator_Precedence_Table.htm

so your code can be more specifically written as 

printf("%d,%d,%d",i|(j&j)|i,i|(j&j)|i,i^j);

(j&j)=1000 AND 1000=1000=j(taking only lower 4 bits)

now the code become $i\mid j\mid i\Rightarrow \left ( i\mid j \right )\mid i\Rightarrow 1100\mid 0100= 1100$ (as "| " is left associative)

also $i\Lambda j\Rightarrow (1000 \Theta 0100)= 1100$(XOR)

so answer is 1100,1100,1100=(12,12,12)

A)

• edited by
2 2 votes
ans will be A  12,12,12,

| bitwise or

& bitwise and

^ bitwise xor

now i=4 in bits 100  , j=8 in bits 1000   j&j =1000 or 8 so i | j&j= 4|8=12|4=12

so first 2 values will be 12 and 12

i^j=0100 xor 1000 =1100 so it is also 12
Position:
Show:

Related questions

5 5 votes
2 2 answers
738
738 views
amar100 asked Nov 3, 2024
738 views
#include <stdio.h int main() {short a[3] = {3, 6, 9, 12, 15, 18};printf("%d\n", *(a + 1) );return 0; }The output is 15. How is the output is 15? , In my thinking it must...
1 1 vote
2 2 answers
2.4k
2.4k views
bharti asked Aug 23, 2017
2,382 views
#include "stdio.h" int * gPtr;int main(){int * lPtr = NULL;if(gPtr == lPtr){printf("Equal!");}else{printf("Not Equal");}return 0;}what will be the outpout :A. it will alw...
2 2 votes
4 4 answers
1.8k
1.8k views
Anil Khatri asked Sep 9, 2016
1,758 views
What will be the output of the program?#include<stdio.h int main() { const c = -11; const int d = 34; printf("%d, %d\n", c, d); return 0; } A. Error B. -1...
0 0 votes
1 1 answer
935
935 views
Anil Khatri asked Sep 8, 2016
935 views
What will be the output of the program assuming that the array begins at the location 1002 and size of an integer is 4 bytes?#include<stdio.h>int main(){ int a[3][4] =...