- การเพิ่มหรือลบค่าของพอร์ยเตอร์ จะหมายถึงการเปลี่ยนตำแหน่งของพอร์ยเตอร์ที่ชี้ไปที่อาเรย์
- การบวก หรือลบ พอร์ยเตอร์ ไม่ได้ เพิ่มตามจำนวนที่บวกเข้าไป แต่จะเพิ่มตามขนาดของชนิดข้อมูล ตามจำนวนครั้งนั้น เช่น ถ้าทำการเพิ่มค่าพอร์ยเตอร์ชนิด int เข้าไป 1 .ค่าจริงๆจะเพิ่มไป 4 bytes ซึ่งก็คือตัวถัดไปนั่นเอง
- อย่าทำการคูณ หรือ หาร พอร์ยเตอร์
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(void) | |
{ | |
int a[] = {0,1,2,3,4,5,6,7,8,9}; | |
int i,*pa; | |
pa = a; | |
//printf("%d %d\n",pa,&a[0]); | |
for(i = 0 ; i < 10 ;i++) | |
{ | |
printf("a[%d] : %d %d\n",i,&a[i],pa ); | |
*pa++; | |
} | |
//" With great power, comes great responsibility" | |
return 0; | |
} |