# C Programming - Bitwise Operators - Discussion

Discussion Forum : Bitwise Operators - Find Output of Program (Q.No. 12)

12.

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;
}
```

Discussion:

25 comments Page 1 of 3.
VISHAL VANAKI said:
5 years ago

4 = 0100

8 = 1000

Let taken 1=true and 0=false.

| means "or" operator i.e. only false to false condition become false but in other cases become a true condition.

& means "and" operator i.e. only true and true condition become true but in other cases it becomes false.

^ means "double implication" i.e. true, false condition and false, true conditions become true but in other cases it shows false.

Then,

i|j = 0100 | 1000 = 1100 = 12

j|i = 1000 | 0100 = 1100 = 12

and then i|j&j|i = 1100 & 1100 = 1100 = 12

So first condition prints 12

And third condition also prints 12.

In the second condition following '&&' is operator shows true prints 1 or false prints 0 for the following condition. So 12&12 = 12 so it is true so it prints 1.

That's it.

8 = 1000

Let taken 1=true and 0=false.

| means "or" operator i.e. only false to false condition become false but in other cases become a true condition.

& means "and" operator i.e. only true and true condition become true but in other cases it becomes false.

^ means "double implication" i.e. true, false condition and false, true conditions become true but in other cases it shows false.

Then,

i|j = 0100 | 1000 = 1100 = 12

j|i = 1000 | 0100 = 1100 = 12

and then i|j&j|i = 1100 & 1100 = 1100 = 12

So first condition prints 12

And third condition also prints 12.

In the second condition following '&&' is operator shows true prints 1 or false prints 0 for the following condition. So 12&12 = 12 so it is true so it prints 1.

That's it.

(1)

Yasaswini said:
6 years ago

@Sana.

X and y values are defined as constant.

So values don't change.

The answer is 50 60 110.

If it is wrong pls tell me how it comes?

X and y values are defined as constant.

So values don't change.

The answer is 50 60 110.

If it is wrong pls tell me how it comes?

Hayyan said:
6 years ago

| what is this symbol means?

Anish Kumar said:
7 years ago

An unary operator has higher precedence than arithmetic operator so why pre-increment and pre-decrement will happen first ++x + --y i.e. 51 + 59 = 110.

x=50 ++x=51;.

x=50 ++x=51;.

Lokesh said:
8 years ago

For i|j&&j|i or operator has high precedence so j|i=12 and i|j=12.

Result of i|j && result of j|i is true because in && operator it checks both operands are non zero.

So it produces 1 as its output.

Result of i|j && result of j|i is true because in && operator it checks both operands are non zero.

So it produces 1 as its output.

Tarun Ghosh said:
8 years ago

^ this is binary XOR operator. Perform Bit-wise XOR operation Means odd no. of 1 is 1 otherwise 0. Then you will get your answer.

Aalapini said:
8 years ago

Can some one explain i^j part? The function of ^ operator specifically.

Sana said:
9 years ago

Can any one please tell me if i=4 and j=8 then how i&&j and i||j done?

Sana said:
9 years ago

51 59 110 is correct.

Sudha said:
9 years ago

@Neetu.

The output is:

51 59 110

The correct or not.

Please anyone tell me.

The output is:

51 59 110

The correct or not.

Please anyone tell me.

Post your comments here:

Your comments will be displayed after verification.

Quick links

Quantitative Aptitude

Verbal (English)

Reasoning

Programming

Interview

Placement Papers

© IndiaBIX™ Technologies