array is used for static memory allocation whereas pointer is used for dynamic memory allocation.
pointers points to the value stored at a particular address whereas like array[10] has 10 values stored consequently in addresses. Initialisation of size of array while declaring its datatype is necessary but declaring while initialing is not necessary for pointers
pointers are mainly used when we need to do address manipulation. int *p , a[10]; ++p or p++ is valid but a++ or --a is not valid. secondly pointers can be used for dynamic memory allocation unlike arrays which need the help of structure. thirdly compilers adot pointer notation internally even if we use arrays in program.
Array is an finite collection of similar data type.Which stores in the adjacent memory. Eg: int a[20]. Explanation: This array carries 20 integer values.It occupies 40 bytes continuously.
Pointer is used to find the value of an address location. Eg: int *a; Explanation: In this the pointer variable 'a' have any address.If we declared that the variable pointer variable it stores value of that particular variable.
in more easy words pointers addresses the first element in an array moreover using this pointer we can declare an array (dynamic memory allocation) and can access the elements by manipulating the address pointer(*p) like ++p,p++ or --p,p--. But in an array all the elements has an associated index through which we can access the particular elements.
Eg: ___________________________ | 10 | 20 | 30 | 40 | 50 | --------------------------- [0] [1] [2] [3] [4] --------------------------- given above is a static array with associated indices. the numbers in square brackets ([]) indicates the respective element index.
to access the elements we need to code like - a[0],a[1],a[2] etc.
but in the case of a pointer (*p) p will hold the address of the a[0]th element of the array a and we can access the subsequent elements by manipulating this address pointer.
Note: Pointers always hold memory address of variable not their value. i.e. why a pointer is called a memory variable.
fundamental difference is array is a memory location of similar data types while pointers are memory addresses (i.e variables of that store address) when arguments are passed to functions as arrays it should be noted that its not the size of the array that is passed or the entire array but the address of the first location of the array. Array name itself can be treated as pointer.
pointer is a variable which holds the address of another variable. Array is a sequential collection of same data type. Memory allocation in array is stack memory. Memory allocation of pointer is heap memory.