I have this program that makes and populates an array. Then it is sent to a function called reverse, which reverses the order in the array. The compiler keeps giving errors. I'm not quite sure why.
CODE
Code:void reverse(int* array, int size) { for (int i = 0; i < size/2; i++) { int temp = array[i]; array[i] = array[size-i]; array[size-i] = temp; } // end of for loop } // end of reverse int main( int argc, char** argv ) { int array[8]; // get and print size of the array int size = sizeof(array) / sizeof(array[0]); printf("Size is %d\n", size); // populate array for (int i = 0; i < size; i++) { array[i] = i; } // end of for loop // display array before reversing for (int i = 0; i < size; i++) { printf("%d ", array[i]); } // end of for loop // new line printf("\n"); // reverse the array reverse(&array, size); // display the array again after reversing for (int i = 0;i < size; i++) { printf("%d ", array[i]); } // end of for loop } // end of main
It keeps giving me this error
main.cc:17:14: error: indirection requires pointer operand ('int' invalid)
int temp = *array[i];
^~~~~~~~~
main.cc:18:3: error: indirection requires pointer operand ('int' invalid)
*array[i] = *array[size-i];
^~~~~~~~~
main.cc:18:15: error: indirection requires pointer operand ('int' invalid)
*array[i] = *array[size-i];
^~~~~~~~~~~~~~
main.cc:19:3: error: indirection requires pointer operand ('int' invalid)
*array[size-i] = temp;
^~~~~~~~~~~~~~
4 errors generated.
make: *** [main.o] Error 1




Reply With Quote
