c - 方括号内的指针?
问题描述
考虑以下代码:
#include <stdio.h>
int main(void){
char *p="A for Apple";
char q[15]="B for Ball";
printf("x=%c y=%c\n",*(p+10)-2,*(&q[4]-2));
printf("u=%c v=%c w=%d\n",p[8],*q+8,8[p]-q[8]);
return 0;
}
输出:
x=c y=f
u=p v=J
w=4
问题,我在这里确定如何w=4
评估。
是什么8[p]
意思?
解决方案
a[x]
是 的简写*(a + x)
。因此,a[x]
等价于表达式x[a]
。(当然,同样适用8[p]
;p[8]
))
推荐阅读
- java - Java:无法使用 for 循环“蛮力”方程系统
- c# - 无法导入 System.Windows.Data
- azure - 如何重命名 Azure 应用服务证书
- typescript - 如何在快递上返回完整的详细错误?
- bash - 我可以为 bash 脚本(如 C++“#pragma once”)创建一个评估一次的标头吗?
- swiftui - 将单元格动态添加到 SwiftUI LazyGrid
- xquery - ¿如何替换和插入新节点?
- python - 用 php 运行 python 脚本
- powerbi - 在列中提取代码 - Power BI
- c# - Azure 持久功能编排 GetInput 不起作用