c指针算术与数字和地址混淆

  • 本文关键字:地址 数字 指针 c pointers
  • 更新时间 :
  • 英文 :


我对如何解决这个问题感到困惑:

4 - (( h + 4 ) - &h[6]) + &h[2] + 5 + (&h[3] - (h+6))

我的方法是:

4 - (( &h[4] - &h[6]) + &h[2] + 5 + (&h[3] - &h[6])) // &h[4] - &h[6] + &h[2] = 0 (is this correct?)
4 - ( 0 + 5 + (&h[3] - &h[6])) // &h[3] - &h[6] = -3 
4 - ( 5 -3)) //
4 - ( 2))
2

但这是不正确的

我是这样看的:

<>之前4 - ((h + 4) - h [6]) + h [2] + 5 + (h [3] - (h + 6))//int PTR int PTR int PTR//将a &a[i]转换为(a + i)(4) - (h + 4 - (h + 6)) + (h + 2) + 5 + ((h + 3) - (h + 6))//int PTR int PTR int PTR int PTR int PTR int4 - (-2) + (h + 2) + 5 + (-3)//int int PTR6 + (h + 2) + 2//int PTR int intH + 10//ptr int——与&h[10]相同

最新更新