อาร์เรย์ของพอยน์เตอร์
เช่นเดียวกับประเภทข้อมูลอื่นๆ เราสามารถประกาศอาร์เรย์ตัวชี้ได้
ประกาศ
datatype *pointername [size];
ตัวอย่างเช่น int *p[5]; //แสดงอาร์เรย์ของพอยน์เตอร์ที่สามารถเก็บที่อยู่องค์ประกอบจำนวนเต็มได้ 5 รายการ

การเริ่มต้น
'&' ใช้สำหรับการเริ่มต้น
ตัวอย่างเช่น
int a[3] = {10,20,30};
int *p[3], i;
for (i=0; i<3; i++) (or) for (i=0; i<3,i++)
p[i] = &a[i];
p[i] = a+i; การเข้าถึง
ตัวดำเนินการทางอ้อม (*) ใช้สำหรับการเข้าถึง
ตัวอย่างเช่น
for (i=0, i<3; i++)
printf ("%d" *p[i]); ตัวอย่าง
#include<stdio.h>
main (){
int a[3] = {10,20,30};
int *p[3],i;
for (i=0; i<3; i++)
p[i] = &a[i]; //initializing base address of array
printf (elements of the array are”)
for (i=0; i<3; i++)
printf ("%d \t", *p[i]); //printing array of pointers
getch();
} ผลลัพธ์
elements at the array are : 10 20 30
ตัวชี้ไปยังตัวชี้
ตัวชี้ไปยังตัวชี้เป็นตัวแปรที่เก็บที่อยู่ของตัวชี้อื่น
ประกาศ
datatype ** pointer_name;
ตัวอย่างเช่น int **p; //p เป็นตัวชี้ไปยังตัวชี้
การเริ่มต้น
'&' ใช้สำหรับการเริ่มต้น
เช่น −
int a = 10; int *p; int **q; p = &a;
การเข้าถึง
ตัวดำเนินการทางอ้อม (*) ใช้สำหรับการเข้าถึง
ตัวอย่าง
#include<stdio.h>
main (){
int a = 10;
int *p;
int **q;
p = &a;
q = &p;
printf("a =%d",a);
printf("a value through pointer = %d", *p);
printf("a value through pointer to pointer = %d", **q);
} ผลลัพธ์
a=10 a value through pointer = 10 a value through pointer to pointer = 10