I'm new to arrays, so I'm not sure where the syntax error is coming from. This program is for C, not C++.
Code:
#include <stdio.h>
#include <stdlib.h>
void show (const int a[], int size);
void reverse (int a[], int size);
int main (void)
{
int a[] = {2,4,6,8};
show(a, 4);
reverse(a, 4);
show(a, 4);
system("pause");
}
void show (const int a[], int size)
{
int i;
for (i=0; i<size; ++i)
{
printf("%i%s", a[i], a[i]==a[size-1]?"\n":", ");
}
}
void reverse (int a[], int size)
{
int i;
int j=0;
int temp[]=a[]; //temporary array for storing old values
for (i=size-1; i>=0; --i)
{
temp[i]=a[j];
++j;
}
}
This problem only occurred after adding the void reverse function.
The exact error is:
error C2059: syntax error : ']'
I'm also wondering if temp[i]=a[j] will permanently change a[]'s values in the main function?