num*_*l25 31 c c++ syntax pointers operators
当一个物体在开头有2个星号时是什么意思?
**variable
Run Code Online (Sandbox Code Playgroud)
Ada*_*eld 47
在声明中,它意味着它是指向指针的指针:
int **x; // declare x as a pointer to a pointer to an int
Run Code Online (Sandbox Code Playgroud)
使用它时,它会两次使用它:
int x = 1;
int *y = &x; // declare y as a pointer to x
int **z = &y; // declare z as a pointer to y
**z = 2; // sets the thing pointed to (the thing pointed to by z) to 2
// i.e., sets x to 2
Run Code Online (Sandbox Code Playgroud)
Inc*_*ito 29
它是指向指针的指针.有关更多详细信息,您可以检查:指向指针
编辑例如,动态分配多维数组可能很好:
喜欢 :
#include <stdlib.h>
int **array;
array = malloc(nrows * sizeof(int *));
if(array == NULL)
{
fprintf(stderr, "out of memory\n");
exit or return
}
for(i = 0; i < nrows; i++)
{
array[i] = malloc(ncolumns * sizeof(int));
if(array[i] == NULL)
{
fprintf(stderr, "out of memory\n");
exit or return
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
59102 次 |
| 最近记录: |