Basically, there is a difference between the variable and pointer variable. Variable is able to hold the value of appropriate data type. But the pointer is a variable which holds the address of another variable. So pointer is variable which is capable to hold the address of appropriate data type variable. There is a slight difference in the declaration of variable and pointer variable.
Variable declaration is as follows
data type variable name; e.g. int a;
Pointer variable declaration is as follows
data type * pointer variable name;
e.g int * p;
here * indicates that the variable is a pointer variable.
Now array is nothing but the group of similar data items with a common name. Example for declaring int array of five elements is as follows.
here arr is the name of the array, which is having five integers as elements of the array. Array elements are stored in a contiguous memory location. As array starts from zeroth element so array name is nothing but the address of a zeroth element of the array.
So it is possible to write the statement like p=arr; Here p is a integer pointer variable which is able to hold the address of an integer variable and arr is nothing but the address of the zeroth element of an array. So using this pointer p we can access array elements. When the statement p++ arises, it means p is pointed to next element of an array. The general statement about p++ is that when the pointer is incremented by one it is incremented by the size of the data type it is pointing. So using this technique we can access, process array elements.
Below is the program which finds the required element from the array using the pointer to an array. Please include and header files in the beginning of the program.
int * p;
cout<<"Enter any five numbers\n";
cout<<"\nEntered numbers are as follows\n";
cout<<"\nEnter the number to found out\n";
cout<<"\nYour required number "< c=1;
cout<<"\nYour required number "< }