#include<stdio.h>
main()
{
int i=0x12345678;
int *p=&i;
printf("i=%x\n",i);
printf("i=%x\n",*(int *)p);
printf("i=%x\n",*(double *)p);
printf("i=%x\n",*(short int *)p);
char ch='B';
char *cp=&ch;
double d=12.5;
double *dp=&d;
printf("ch=%d at %u d=%f at %u\n",*cp,&ch,*dp,&d);
}
OutPut:
madan@madan-Lenovo-G570:~/madan$ cc pointer1.c
pointer1.c: In function �main�:
pointer1.c:8:1: warning: format �%x� expects argument of type �unsigned int�, but argument 2 has type �double� [-Wformat=]
printf("i=%x\n",*(double *)p);
^
pointer1.c:14:1: warning: format �%u� expects argument of type �unsigned int�, but argument 3 has type �char *� [-Wformat=]
printf("ch=%d at %u d=%f at %u\n",*cp,&ch,*dp,&d);
^
pointer1.c:14:1: warning: format �%u� expects argument of type �unsigned int�, but argument 5 has type �double *� [-Wformat=]
madan@madan-Lenovo-G570:~/madan$ ./a.out
i=12345678
i=12345678
i=7ffffff5
i=5678
ch=66 at 2484735611 d=12.500000 at 2484735616