关于指针的一点儿小知识

来源:互联网 发布:淘宝设计师 编辑:程序博客网 时间:2024/05/08 05:07

博主: 这个娃说的挺对胃口的,转了

1:转自:http://www.360doc.com/content/11/0925/16/6527018_151129737.shtml

很多人把指针说的洪水猛兽似的,其实就那么回事儿嘛

 

2:字符指针与整形指针的一点儿分析

转自:http://blog.csdn.net/ghost1236/article/details/6309809 

不错滴。

 

 

#include<stdio.h>
#include<stdlib.h>
/*int main(void)
{
 int *pi;
 char * pc;
 long * pl;
 char a[]="abcdefg";
 int b = 10000;
 printf("the sizeof int  * is %d \n",sizeof(pi));
 printf("the sizeof char * is %d \n",sizeof(pc));
 printf("the sizeof long * is %d \n",sizeof(pl));
 pi = a; 
 printf("array: the sizeof int   is %s \n",pi);
 pc = a;
 printf("array:the sizeof char  is %s \n",pc);
 pl = a; 
 printf("array:the sizeof long  is %s \n",pl);
 *pi = b;
 printf("char number: the sizeof int is %d \n",*pi);
 *pc = b;
 printf("char number: the sizeof char is %d \n",*pi);
 *pl = b;
 printf("char number: the sizeof long is %d \n",*pi);

 return 0;
}*/


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

  char day[15] = "abcdefghijklmn";
  char* strTmp = "opqrstuvwxyz";

  printf("&day is %x\n",&day);
  printf("&day[0] is %x\n",&day[0]);
  printf("day is %x\n",day);
 
  printf("\n&strTmp is %x\n",&strTmp);
  printf("&strTmp[0] is %x\n",&strTmp[0]);
  printf("strTmp is %x\n",strTmp);
 
  getchar();
  return 0;
}*/
int main(int argc, char *argv[])
{
 char *c = "123456";
 int  *i = "123456";

 printf("&c is %d\n",&c);
 printf("c is %x\n",c);
 printf("*c is %s\n",c);
 c++;
 printf("c++\n&c is %d\n",&c);
 printf("c is %x\n",c);
 printf("*c is %s\n",c);
 *c++;
 printf("*c++\n&c is %d\n",&c);
 printf("c is %x\n",c);
 printf("*c is %s\n",c);


 printf("\n\n\n&i is %d\n",&i);
 printf("i is %x\n",i);
 printf("*i is %s\n",i);
 i++;
 printf("2222 i++\n&i is %d\n",&i);
 printf("i is %x\n",i);
 printf("*i is %s\n",i);
 
 
 printf("3333*i++\n  &i is %d\n",&i);
 printf("i is %x\n",i);
 printf("*i is %s \n",i);

    return 0;
}