Pointer to Array in c

when an array is declared to a pointer, the memory locations differ according to their datatype sizes in a sequence.it depends on the base address, let’s see one example

example

we will declare one array called arr

int arr[4] = { 1, 2, 3, 4 };

the address of all other subsets of the array depends on base value arr[0].so,we will assume base value as 6000 all other values will be increased by 2, this is just an example

pointer with array

the name of array is always points to the address of the first element in the array.

arr is equal to &arr[0] by default

the address refers to the pointer

arr[0] is equivalent to arr (value of an address of the pointer) similary &arr[1] is equivalent to (arr + 1) AND, arr[1] is equivalent to (arr + 1). &arr[2] is equivalent to (arr + 2) AND, arr[2] is equivalent to (arr + 2). &arr[3] is equivalent to (arr + 1) AND, arr[3] is equivalent to (arr + 3). . . &arr[i] is equivalent to (arr + i) AND, arr[i] is equivalent to *(arr + i).

example for the above rules:

#include
int main()
{
int i, classes[6],sum = 0;
printf("Enter 6 numbers:\n");
for(i = 0; i < 6; ++i)
{
// (classes + i) is equivalent to &classes[i]
scanf("%d",(classes + i));
// *(classes + i) is equivalent to classes[i]
sum += *(classes + i);
}
printf("Sum = %d", sum);
return 0;
}

output:

Enter 6 numbers:
1 2 4 6 83 2
Sum = 98

Pointer to Array

we will see one example .we can access every element in an array using p++ (pointer)