What is the difference between a pointer and an array?
Pointers are variable. You point to one variable, and after sometime you start pointing to another variable with the same pointer.
Example:
int x = 1;
int *p = &x;
//in the next line you can say
*p = &b; // if b has been initialized.
Array name is the address to the first index of array. Array name is a CONSTANT Pointer => You cannot do a = a + 1; if a is an array. It will generate an error since it always point to same location.
When we do for example cout << *(a+1); (a is arraY) We give an offset and elements at 2nd index is printed. a still points to the first location.
Pointers are variable. You point to one variable, and after sometime you start pointing to another variable with the same pointer.
Example:
int x = 1;
int *p = &x;
//in the next line you can say
*p = &b; // if b has been initialized.
Array name is the address to the first index of array. Array name is a CONSTANT Pointer => You cannot do a = a + 1; if a is an array. It will generate an error since it always point to same location.
When we do for example cout << *(a+1); (a is arraY) We give an offset and elements at 2nd index is printed. a still points to the first location.