gyan said:
why following's output is noting in C program
int a=5;
printf("\n%s\n",(char *)(&a));
`%s` wants a string, ie a char* pointer to a null-terminated
sequence of characters. `a`, whose address you have taken and
then forcibly (but reversibly) converted to `char*`, isn't
any sequence of characters at all, so whatever you get out
isn't C's responsibility any more - it will be an accident
of the implementation. (Or even a deliberate feature, but
usually not.)
*As it happens*, the underlying implementation may not care.
There are some bytes in the object `a`; it may treat them
as characters and print until it finds a zero byte. If you
machine is big-endian, or the character with value 5 is
invisible, you'll get what you got - no visible characters
displayed.
and
following lines give correct output
printf("\n%d\n",*(int *)(&a));
Because you ask to print an int, and what you give it is
*(int *)(&a)
which is
*(&a)
because the cast is redundant, &a already being int*, and
*&a === a
by the co-definitions of * and &.