# arrays doubt

• 11-20-2004
j0nnyX
arrays doubt
I've a little doubt in arrays,

i'm trying to make a program that change, the 1st element of an array ( v[0] ) for the last one ( v[5] for example).

i call the funcion change:
Code:

```void change(int v[], int x){ int i , t , x; for(i=0;i<=n-1;i++){ x=v[0]; t=v[n-1]; v[0]=t; v[n-1]=x; } for(i=0;i<=n-1;i++){ printf("%d\n", v[i]); } }```
and i use these main:
Code:

```int main(){ int a[SIZE]={8,5,6,9,1,3}, m=6, i; for(i=0;i<=m-1;i++){ printf("%d\n"a[i]); } printf("\n\n"); change(a,m); }```
Can anybode tell me what's wrong in the function??
thank u, johnny!
• 11-20-2004
quzah
Quote:

Originally Posted by j0nnyX
I've a little doubt in arrays,
i call the funcion change:
Code:

```void change(int v[], int x){ int i , t , x; for(i=0;i<=n-1;i++){ x=v[0]; t=v[n-1]; v[0]=t; v[n-1]=x; } for(i=0;i<=n-1;i++){ printf("%d\n", v[i]); } }```
Can anybode tell me what's wrong in the function??
thank u, johnny!

Yeah, your compiler can. Did you even try to compile that? For starters, there is no variable named n in the function. Yeah. That'll be a problem...

Quzah.
• 11-20-2004
j0nnyX
so, i should substitute n for the variable x?

yes i try to compile, and the program print 2 equal arrays, equal to the original one.
• 11-20-2004
itsme86
You're shadowing x that's being passed to your function by declaring a second one.
Code:

```void change(int v[], int x){ int i , t , x;```
You should really pay attention to your compiler warnings and errors.
• 11-20-2004
quzah
Quote:

Originally Posted by j0nnyX
yes i try to compile, and the program print 2 equal arrays, equal to the original one.

No it didn't. Not that code. There is no variable n, as I've stated. It will not compile the way you've posted it.

Quzah.