what is the Difference between arrays and pointers?

What is the Difference between arrays and pointers?

- Pointers are used to manipulate data using the address. Pointers use
* operator to access the data pointed to by them
- Arrays use subscripted variables to access and manipulate data.
Array variables can be equivalently written using pointer expression.

Program to show that array and pointers are different
#include  

int main()
{
   int arr[] = {10, 20, 30, 40, 50, 60};
   int *ptr = arr;
   
   // sizof(int) * (number of element in arr[]) is printed
   printf("Size of arr[] %ld\n", sizeof(arr));

   // sizeof a pointer is printed which is same for all type
   // of pointers (char *, void *, etc)
   printf("Size of ptr %ld", sizeof(ptr));
   return 0;
}

Output:
Size of arr[] 24
Size of ptr 8
Assigning any address to an array variable is not allowed.

Keywords:
relation between array and pointer in c
differentiate between array of pointers and pointers to array
difference between array and pointer in c in hindi
difference between array and pointer in hindi
which of arrays or pointers are faster
difference between array and structure
array vs pointer in c
difference between pointer and reference

No comments: