Reputation: 175
#include<stdio.h>
int main() {
int x;
x=~!printf;
printf("%x",x);
}
can some one explain me the process to derive the output of this program.
Upvotes: 2
Views: 201
Reputation: 229561
printf
is a pointer to the printf
function - thus it's ultimately an integer of some sort. !
is unary NOT, meaning it returns 0
if the operand is true, and 1
is the operand is false. Since printf
is true (non-zero, because the function is defined), the subexpression so far is 0
.~
is bitwise complement. It flips all the bits of the binary number it is given. Since it is given 0
, this will return 0xffffffff
.x
and printed out in hexadecimal. On a 64-bit machine you might instead get 0xffffffffffffffff
, though I'm not entirely certain.
Upvotes: 8