相关疑难解决方法(0)

我们可以拥有多少级别的指针?

*单个变量中允许多少个指针()?

让我们考虑以下示例.

int a = 10;
int *p = &a;
Run Code Online (Sandbox Code Playgroud)

同样我们也可以

int **q = &p;
int ***r = &q;
Run Code Online (Sandbox Code Playgroud)

等等.

例如,

int ****************zz;
Run Code Online (Sandbox Code Playgroud)

c c++ pointers

432
推荐指数
11
解决办法
4万
查看次数

C中的三重指针:这是风格问题吗?

我觉得C中的三分指针被视为"坏".对我来说,有时使用它们是有道理的.

从基础开始,单指针有两个目的:创建数组,并允许函数更改其内容(通过引用传递):

char *a;
a = malloc...
Run Code Online (Sandbox Code Playgroud)

要么

void foo (char *c); //means I'm going to modify the parameter in foo.
{ *c = 'f'; }

char a;
foo(&a);
Run Code Online (Sandbox Code Playgroud)

双指针可以是2D阵列(或阵列的阵列中,由于每个"列"或"行"不必具有相同的长度).我个人喜欢在需要传递一维数组时使用它:

void foo (char **c); //means I'm going to modify the elements of an array in foo.
{ (*c)[0] = 'f'; }

char *a;
a = malloc...
foo(&a);
Run Code Online (Sandbox Code Playgroud)

对我来说,这有助于描述foo正在做什么.但是,没有必要:

void foo (char *c); //am I modifying a char or just passing a char array?
{ c[0] = …
Run Code Online (Sandbox Code Playgroud)

c pointers coding-style

8
推荐指数
3
解决办法
2万
查看次数

标签 统计

c ×2

pointers ×2

c++ ×1

coding-style ×1