Explanation of solution needed

Please explain how the answer is coming

hello @pd.pankajdahiya

pls share that question with me in which u have doubt

Q9. bitmask 1<<32 32 bit long long x = (1 << 32) ; What will be the value of x ?

it will result in compilation error. because 1 is int and we can shift it till [0…31] not more than that.

In answer there are 4 options- compile error, 2^31, 2^32, none(correct), so is it a runtime error and why?

its a compile error. compiler will check this thing at the time of compiling

u can run the same program and check

Finished in N/A Line 2: Char 23: runtime error: shift exponent 32 is too large for 32-bit type ‘int’ (solution.cpp) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior prog_joined.cpp:7:23

your compiler might not be checking this at compile time.

But the solution of the questions says its none of the above so finally its a warning/runtime . is it?

its compilation error->
ss

image

ok , anwer will be compiler dependent , some may give compilation error (like cb compiler) and some may not (like ur compiler).

go with none of these

ok thank you. I got it.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.