1. Pointer to integral type
#include <stdio.h>
int main ()
{
int a=5;
int *p;
p=&a;
printf ("a=%d &a=%x *p=%d p=%x \ n", a,&a,*p,p);
printf ("Pointer variable P's address =%x\n", &p);
}
A |
&a |
*p |
P |
5 |
12ff7c |
5 |
12ff7c |
2. Pointer to character
#include <stdio.h>
int main ()
{
Char str[5]= "ABCD";
Char *p;
P=STR;
printf ("str=%s p=%s str=%x *p=%c p=%x \ n", str, p, str, *p, p);
printf ("Pointer variable P's address =%x\n", &p);
}
Why is the integer pointer p output the address, and the character pointer output is a string, the character pointer is not stored in the address?
Here we explain: for the pointer you use the%s output is a string, with%x is the address
3 . Pointer to an integral type pointer
#include <stdio.h>
int main ()
{
int a[6]={1,2,3,4,5};
int *p=a;
int * (*PTR) =&p; Because it is a pointer, so the address is stored, so to add &
printf ("a=%x\n", a); That is, the first address of the array 12ff68
printf ("p=%x\n", p); The value stored by the P pointer variable is the first address of the array 12ff68
printf ("&p=%x\n", &p); The address of the P pointer variable itself is 12FF64
printf ("ptr=%x\n", PTR); The PTR pointer variable stores the address of the P pointer variable 12ff64
printf ("&ptr=%x\n", &ptr); The address of the PTR pointer itself 12ff60
printf ("*ptr=%x\n", *ptr); *ptr refers to the 12ff68 address.
printf ("**ptr=%d\n", **ptr); **ptr =1
}
General pointers and pointers to pointers