We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
最近重新拾起C语言,Python 用得久了对指针的操作已经非常生疏了,在这里对遇到的一些指针操作上的陷阱进行整理记录。
在初始化数组的时候遇到后一个数组的指针与前一个重叠:
size_t n = 6; size_t f1[n]; size_t f2[n]; size_t ls[2][n-1]; printf("&ls[1][5] = %p\n&f2[0] = %p", &ls[1][5], f2);
输出结果为:
&ls[1][5] = 0x7fff501f3730 &f2[0] = 0x7fff501f3730
用 malloc 动态分配或者将 size_t f2[n] 放到 ls 声明的后面不会有问题,那上面出现这个问题的原因是什么呢?
原因
The text was updated successfully, but these errors were encountered:
rainyear
No branches or pull requests
最近重新拾起C语言,Python 用得久了对指针的操作已经非常生疏了,在这里对遇到的一些指针操作上的陷阱进行整理记录。
1. 数组初始化导致指针重叠
在初始化数组的时候遇到后一个数组的指针与前一个重叠:
输出结果为:
用 malloc 动态分配或者将 size_t f2[n] 放到 ls 声明的后面不会有问题,那上面出现这个问题的原因是什么呢?
原因
2. 二维数组只声明未初始化
The text was updated successfully, but these errors were encountered: