we have to predict the output of the following code kindly help I could not understand the codehttps://ide.codingblocks.com/s/446775
Please help with the code
hello @av8055
what u havent understood.
here we have an int variable x which is holding 135.
then we have a char pointer p which hold address of variable x.
and then we are printing *p .
we are getting output as -121 becuase
signed char has range [-128, 127]
so if we store 128 it will treated as -128 (becuase of overflow)
similiarly 129 will be treated as -127 …
130 will be treated as -126
…
135 will be treated as -121
oh tank you I was taking range of unsigned char😅
can you please explain the meaning of the statement :: p = (char*) &x;
&x -> will return address of variable x , but becuase data type of x is int , the address returned will for int
but we want to store it in char type pointer ,hence we need to explicitly typecast it .
thats why we have p=(char*) &x;