Typecasting in pointer

#include<conio.h>
#include<stdio.h>
main()
{
int a=1025;
int *p =&a;
printf("Addres of a = %d, and value of a =%d \n",p , *p );
printf("Addres of a+1 = %d, and value at a+1 =%d\n",(p+1) , *(p+1) );
char *p0; //char pointer initialiseed
p0=(char*)p; // char pointer typecasted to int
printf("the casted char pointer address =%d, and value = %d\n",p0,*p0 );
/** Generic pointer**/
void *p1; //generic pointer initialised
p1=p; //storing address of a
printf(" Address of a (with use of void pointer) = %d",p1 );
}

                      OUTPUT

Addres of a = 2686736, and value of a =1025
Addres of a+1 = 2686740, and value at a+1 =73
the casted char pointer address =2686736, and value = 1
Address of a (with use of void pointer) = 2686736

No comments:

Post a Comment