Computer Science, asked by raj40539933, 3 months ago

int a=1;
a=5|| 2 || 1;
a<<=5;
a^=0x1F;
printf("%d", a);
return 0;​

Answers

Answered by poojan
10

63 is the output.

Explanation:

Program:

#include <stdio.h>

int main()

{

int a=1;

a=5|| 2 || 1 ;

a<<=5;

a^=0x1F;

printf("%d", a);

return 0;

}

Initially, a is assigned with 1.

In the next line, || (OR) operator is used which returns 1 if true, else 0. Any non-zero number as an expression returns true. So, 5 || 2 || 1 returns 1.

Next, the left-shift operator is used, saying the bit values should be shifted by 5 bits to left.

As 1, the bit value is: 0000 0001

After shifting 5-bit positions to the left, we get: 0010 0000 which equals 32 in decimal format.

So, now a = 32

Then, in the expression a^=0x1F, the XOR '^' operator is used. And the XOR should be done between 32 and 0x1F.

0x1F is a hexadecimal number. F=15 in hexadecimal.

It's conversion to decimal is: (1 x 16¹) + (15 x 16⁰) = 16+15 = 31

So, a = 32 ^ 31. In XOR => 00=0, 11=0, 01=1, 10=1

XOR:    32 = 0010 0000

            31 = 0001 1111

                 ___________

        32^31 = 0011 1111

0011 1111 = 63 in decimal.

Therefore, a=63 and it is printed.

Learn more:

1. Ch+=2 is equivalent to​

brainly.in/question/21331324

2. A CSS file cannot be linked to a web page. State True or False.

brainly.in/question/21107345

Similar questions