Can someone explain the reason for pointers. i have setup an array like the following.
int* a = NULL;
int n;
cin >> n;
a = new int[n];
This will setup my array size based on the number that a person enters. If I want to load this array with numbers or if the array was a character array, what will pointers do for me?
so if I use pointer in assigning the array and I have a user input 25 different numbers into the array, will the array hold the address of those numbers or the actual numbers?
int a[20]; Gives you an array of exactly 20 ints. No more, no less.
int a* = newint[n]; Gives you an array of 'n' ints. This is useful if the value of 'n' is not known at compile time (like if you get it from a file, or from the user)
so if I use pointer in assigning the array and I have a user input 25 different numbers into the array, will the array hold the address of those numbers or the actual numbers?