当前位置:网站首页>Double pointer - the role of char **, int **

Double pointer - the role of char **, int **

2022-08-09 11:44:00 phil__naiping

The content of this article is very simple, it is to discuss the role of double pointers such as char** and int**.

1, demo

 int a = 10;int* b = &a;int** c = &b;

insert image description here

  • Pointer b points to variable a; the value of variable a can be manipulated through *b.
  • Double pointer c points to pointer b, then *c can manipulate the contents of pointer b.

The crux of the question is what is the content of pointer b?

  • The content of pointer b is the address of variable a.Then adding a value to the pointer c is equivalent to adding a value to &a, which is equivalent to moving the pointer to the buffer a.

We might as well think of a as a buffer
hereInsert image description

Then you can operate on buffer a by adding or subtracting the pointer *c.

2. Summary

Double pointers can be incremented by offsets, moving on the buffer.For example, to write content to the buffer, you can use the double pointer to continuously update the content in the buffer.

原网站

版权声明
本文为[phil__naiping]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/221/202208091129390374.html