更新时间:2022-06-27 00:50:34
在这种情况下, A [4]
是 4
数组中的整数 A
, AP
是整数的指针,所以你分配给一个整数指针,这就是警告。照片所以 AP
现在持有 45
,当你试图去参考它(通过执行 * AP
)你想在地址45,这是一个无效的地址来访问内存,所以你的程序崩溃。
In this case a[4]
is the 4th
integer in the array a
, ap
is a pointer to integer, so you are assigning an integer to a pointer and that's the warning.
So ap
now holds 45
and when you try to de-reference it (by doing *ap
) you are trying to access a memory at address 45, which is an invalid address, so your program crashes.
您应该做的 AP =放大器(A [4]);
或 AP = A + 4;
在 C
数组名衰变为指针,所以 A
指向数组的第一个元素。
这样, A
等同于&功放;(A [0])
In c
array names decays to pointer, so a
points to the 1st element of the array.
In this way, a
is equivalent to &(a[0])
.