C中的指针数组?
发布时间:2020-12-16 03:32:02 所属栏目:百科 来源:网络整理
导读:参见英文答案 Are negative array indexes allowed in C?7个 指针是一个很难确定的主题,但是我遇到了这个片段而我无法弄清楚p [-1]是什么: #include stdio.h int main(void) { int t[10] = { 1,2,3,4,5,6,7,8,9,10 },*p = t; p += 2; p += p[-1]; printf("%
参见英文答案 >
Are negative array indexes allowed in C?7个
指针是一个很难确定的主题,但是我遇到了这个片段而我无法弄清楚p [-1]是什么: #include <stdio.h> int main(void) { int t[10] = { 1,2,3,4,5,6,7,8,9,10 },*p = t; p += 2; p += p[-1]; printf("%d",*p); return 0; } 解决方法
每当你在C中看到类似[b]的表达式时,你就可以在心理上认为*(a b)正在发生.
所以,它只是“一个p指向现在之前元素的内容”. 由于p在t 2,p [-1]指t [2(-1)],即t [1]. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |