Why is the below code giving a warning?
#include <stdio.h>
int main()
{
int arr[3] = {1,2,3};
int *ptr, *ptr1;
ptr = &arr;
ptr1 = arr;
printf("ptr is %p\t ptr1 is %p\n",ptr, ptr1);
ptr++;
ptr1++;
printf("ptr is %p\t ptr1 is %p\n",ptr, ptr1);
return 0;
}
$ gcc test.c -o test
test.c: In function ‘main’:
test.c:6:6: warning: assignment from incompatible pointer type [enabled by default]
ptr = &arr;
I also tried changing ptr
to int **ptr
, but it still fails with the same warning. arr
is a pointer; I am storing it in a pointer. What is the mistake here?