I just want to know why, when I pass arrays to functions, say, for example, to initialize them, they actually initialize. Since the variables in the inic function are completely independent from the ones in the main function (no pointers involved), how is the inic function able to initialize the values of array v? Isn't array s inside the inic function a separate thing?
#include <stdio.h>
void inic(int s[], int n)
{
int i;
for(i=0; i<n; i++)
s[i]=0;
}
main()
{
int v[10];
int x[20];
inic(v, 10);
inic(x, 20);
}
It might be clearer if I show this example as well:
#include <stdio.h>
void value(int n)
{
n = 2;
}
main()
{
int x=1;
value(x);
printf("X is %d\n", x); //The output would be 1. The function *value* doesn't affect X.
}
So why is it that it's different for arrays?