int meta_size = 24;
node_t* prev;
printf("%lx, ", prev + meta_size );
printf("%lx, ", prev);
printf("%lx, ", meta_size);
输出:1519240,1519000,18 这是怎么回事?
答案 0 :(得分:2)
Prev是一个单元化指针,它包含(一个随机的,因为它没有被初始化)内存地址。
printf("%lx, ", prev + meta_size );//Prints the memory address prev is pointing to + (sizeof(node_t) * meta_size)
printf("%lx, ", prev); //Prints the memory address prev is pointing to
printf("%lx, ", meta_size); //Prints meta_size, 18 is 24 in hexidecimal, because of the 'x' in %lx
但是,前两行是未定义的行为,因为指针应使用%p
打印答案 1 :(得分:0)
如果你做sizeof(node_t)
我很确定你会获得10.