關於指針與數組關係的分析

數組和指針我認爲可以理解爲 數組是const指針 

指針有數組的所有特性 

數組只是一個不可以更改地址的指針

#include <stdio.h>

int main()
{
char Mat[5]={"1234"};
char *p=Mat;

printf("Mat Index:%x \np   Index:%x ",Mat,p);

printf("\nMat[3]++;\nMat: %s\n  p:%s",Mat,p);
Mat[3]++;
printf("\nMat: %s\n  p:%s",Mat,p);
p[3]++;
printf("\np[3]++;\nMat: %s\n  p:%s",Mat,p);

}
輸出結果:

Mat Index:62fe40
p   Index:62fe40
Mat[3]++;
Mat: 1234
  p:1234
Mat: 1235
  p:1235
p[3]++;
Mat: 1236
  p:1236

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章