下面是使用malloc分配内存的代码:
typedef struct qu_n_t {
int item;
struct qu_n_t *next;
} qu_node_t;
qu_node_t *currentblock = NULL;
qu_node_t *tmp;
currentblock = (qu_node_t *) malloc( 5 * sizeof(qu_node_t) );
tmp = currentblock++;
现在,一旦代码被执行,currentblock指针将被分配到
5 * sizeof(qu_node_t)
的内存地址。如果我使用currentblock,分配给它的地址是什么?这是使用malloc分配的5个块中的第一个块地址吗? 最佳答案
是的,在调用malloc之后,currentblock指向数组中的第一个块。
在下一行之后,tmp指向第一个块,currentblock指向第二个块。
关于c - 使用malloc分配的块的地址,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28372094/