下面是关于二叉树的代码----pos
代表了根据前序遍历pre_str
确定了根节点在中序遍历中的位置.
int pos = strchr(in_str, pre_str[0]) - in_str;
我知道指针就是代表地址的一个 unsigned int
, 我想问的是这样直接用指针加减来得到的位置为什么不考虑到 sizeof(int)
, 是说这些指针都是和数据类型的size
无关的吗? 有错误的话请大家指正下.
迷茫2017-04-17 15:26:45
The offset is already included in the addition and subtraction of pointers. For example, if the pointer of int* is added to n, its memory address is added to n*sizeof(int). It is not directly added or subtracted according to the memory address.