理解指针和指针的指针及其赋值的小例子

理解指针和指针的指针及其赋值的小例子[@more@]

#include
#include

int main(int argc, char *argv[])
{

int n = 5;

int *p;
int **mp;
int *p2;
int *p3;


p = &n;
mp = &p;
p2 = &p;
p3 = p;

printf("----------------------------------n");
printf("size of n is %dn", sizeof(n));
printf("n is %dn", n);
printf("&n is %dn", &n);


printf("----------------------------------n");
printf("size of p is %dn", sizeof(p));
printf("p is %dn", p);
printf("*p is %dn", *p);
printf("&p is %dn", &p);


printf("***********************************n");
printf("size of mp is %dn", sizeof(mp));
printf("mp is %dn", mp);
printf("*mp is %dn", *mp);
printf("*mp is %dn", **mp);
printf("&mp is %dn", &mp);

printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~n");
printf("size of p2 is %dn", sizeof(p2));
printf("m2 is %dn", p2);
printf("*p2 is %dn", *p2);
printf("&p 2is %dn", &p2);


printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~n");
printf("size of p3 is %dn", sizeof(p3));
printf("p3 is %dn", p3);
printf("*p3 is %dn", *p3);
printf("&p3 is %dn", &p3);

system("PAUSE");
return 0;

}


----------------------------------
size of p is 4
p is 2293580
*p is 5
&p is 2293576
***********************************
size of mp is 4
mp is 2293576
*mp is 2293580
*mp is 5
&mp is 2293572
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
size of p2 is 4
m2 is 2293576
*p2 is 2293580
&p 2is 2293568
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
size of p3 is 4
p3 is 2293580
*p3 is 5
&p3 is 2293564

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/640706/viewspace-1055897/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/640706/viewspace-1055897/

你可能感兴趣的:(理解指针和指针的指针及其赋值的小例子)