简体   繁体   中英

What does sizeof(int**) mean?

I am new to C. I saw this line in a program:

grid = calloc(nx,sizeof(int**));

I read that int** means a pointer to a pointer, but what is meant by sizeof(int**) ??

The sizeof operator yields the number of bytes of storage required by its operand. 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 ".

Assuming grid has been declared as

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 . Presumably, whoever wrote the code is looking to allocate enough memory to store nx such pointers.

sizeof(int **) tells you how many bytes an int ** is, similarly to how sizeof(int *) tells you how many bytes an int * is. They just have different levels of indirection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM