#include <stdio.h>
int main(){
int arr[] = {1, 2, 3, 4};
int *p;
p = arr;
printf("%d\n", *p);
printf("%d\n", *arr);
p++;
printf("%d\n", *p);
}
此代码输出:
1
1
2
但是当我们添加如下两行时:
#include <stdio.h>
int main(){
int arr[] = {1, 2, 3, 4};
int *p;
p = arr;
printf("%d\n", *p);
printf("%d\n", *arr);
p++;
printf("%d\n", *p);
arr++;
printf("%d\n", *arr);
}
此代码输出:
C:\Users\Hasnat\Desktop\test.c||In function 'main':|
C:\Users\Hasnat\Desktop\test.c|11|error: lvalue required as increment operand
=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===
为什么我们不能以与增加包含该数组地址的指针相同的方式增加一个数组以获取下一个元素?