array and pointer questions

i was given an assignment by my prof. , but he stated that using pointer notation . the object t=of the program was to write a C++ function ReverseArray using "pointer notation" that will write out the elements of an array of int in reverse order.
his comments were
This is array notation: cout << "The int values you entered are: " << endl; for (int i = 0; i < arraySize; i++) cout << intList[i] << endl; This is pointer notation cout <<*intList<

i have no clue of what he means so im a bit lost , but he returned my program(F) to fix and trying to get someone to explain what i did wrong


this is my code


#include <iostream>

using namespace std;


int *numList; // array of POINTERS to numbers
int arraySize = 0 ; // input area for longest possible number.

int main()
{
void ReverseArray(int* &intArray, int size);





cout << "Enter the size of the new int array: ";
cin >> arraySize;

cout << "\n"; //newline

//(array var) = new (type)[(size taken from user}]

numList = new int[arraySize];

for(int i = 0; i < arraySize; i++)
{
cout << "\nEnter the next number in the array: ";
cin >> numList[i];


}

ReverseArray(numList, arraySize);


return 0;
}//end main

void ReverseArray(int* &intArray, int size)
{
//for each element up to "size"
for (int i=size-1; i>=0; i--)
/*for(int i = 0; i < size; i++)*/
{
cout << "Element " << i << " equals: " << intArray[i] << "." << endl;
cout << numList[i] << endl; // print the numbers
}

system("PAUSE");
}

What he means is that you should use pointer notation instead of array notation. The key to this is to know that if you have an array, say int ar[10], then ar is actually a pointer to the start of a memory segment in which there is room for 10 int's, hence *ar = ar[0] and ar[i] = *(ar+i). This may give you an idea of how to solve the ReverseArray-assignment using pointers instead of arrays.
I dont think im following you .
i thought i allocated memory when i made " void reverseArray(int* &intArray, int size) " when i decleard these variables are they not allocating memory? are you saying change the &intArray to just *ar[10] ???
Hi again.

No. I am saying that there is a relationship between pointers and arrays: "The name of an array is a pointer to the array's first element". So if I need to access the 3rd element in an array I could either write ar[2] or *(ar+2). Or, if you need to print the 5th element, you could do either cout << ar[4] or cout << *(ar+4).

The opposite is also true. If you have a pointer and need to point 4 "slots" further ahead you can do *(ptr+4) or ptr[4].

Put shortly: The notations ar[i] and *(ar+i) are equivalent.
im not following you i still dont see the difference
There is no difference....arrray[i] and *(array+i) are the same.
Topic archived. No new replies allowed.