Double pointer là gì?

Noun None
pointer to pointer
Con trỏ kép

Con trỏ kép (double pointer) là con trỏ (pointer) mà trỏ tới con trỏ khác, con trỏ đầu tiên được sử dụng để lưu trữ địa chỉ của con trỏ thứ hai. Vì vậy, nó được gọi là con trỏ kép (double pointer).

Một chương trình đơn giản để hiểu con trỏ kép (double pointer):


int main() {
   int v = 76;
   int *p1;
   int **p2;
   p1 = &v;
   p2 = &p1;
   printf("Value of v = %d\n", v);
   printf("Value of v using single pointer = %d\n", *p1 );
   printf("Value of v using double pointer = %d\n", **p2);
   return 0;
}

Output:


Value of v = 76
Value of v using single pointer = 76
Value of v using double pointer = 76

Learning English Everyday