#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);
}
This code outputs:
1
1
2
but when we add 2 lines as below:
#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);
}
This code outputs:
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)) ===
Why can not we increment an array in same way we increment pointer containing address of that array to get next element??