[英]What does sizeof(int**) mean?
I am new to C. I saw this line in a program: 我是C语言的新手。我在程序中看到以下行:
grid = calloc(nx,sizeof(int**));
I read that int**
means a pointer to a pointer, but what is meant by sizeof(int**)
?? 我读到int**
是指向指针的指针,但是sizeof(int**)
是什么意思?
The sizeof
operator yields the number of bytes of storage required by its operand. sizeof
运算符产生其操作数所需的存储字节数。 The operand is either an expression or a type enclosed in parentheses. 操作数可以是表达式或括号中的类型。 In this case, the operand is the type int **
, which is "pointer to pointer to int
". 在这种情况下,操作数是类型int **
,它是“指向int
指针”。
Assuming grid
has been declared as 假设grid
已声明为
int ***grid;
then that can be rewritten as 然后可以重写为
grid = calloc(nx, sizeof *grid);
The sizeof
expression is just the number of bytes needed to represent a pointer-to-pointer-to- int
. sizeof
表达式只是表示一个指向int
的指针所需的字节数。 Presumably, whoever wrote the code is looking to allocate enough memory to store nx
such pointers. 据推测,无论谁编写代码,都希望分配足够的内存来存储nx
此类指针。
sizeof(int **)
tells you how many bytes an int **
is, similarly to how sizeof(int *)
tells you how many bytes an int *
is. sizeof(int **)
告诉您int **
字节数,类似于sizeof(int *)
告诉您int *
字节数。 They just have different levels of indirection. 它们只是具有不同级别的间接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.