Caws...
In C arrays are never passed by value. Arrays are always passes by reference (a pointer to the array). Also it is important to understand that you can not pass the size of the array by putting it in the brackets as was done in the previous example. Most of programmers I have read would declare func like this...
Code:
void func( unsigned int array[] );
or this...
Code:
void func( unsigned int *array );
The important point to understand is that all three methods accomplish the same thing.
You can make this function more robust by passing the size of the array as a second parameter...
Code:
void func( unsigned int *array, unsigned int size );
Example:
Code:
#include <stdio.h>
#define NUMBER_OF_ELEMENTS 10
void func( unsigned int *array, int size )
{
int x = 0;
for( ; x < size; x++ )
array[x] = x * x;
}
int main (void)
{
unsigned int array[NUMBER_OF_ELEMENTS] = {0};
int arraysize = sizeof( array )/sizeof( unsigned int );
int x = 0;
func( array, arraysize );
for(; x < arraysize; x++ )
printf("array[%d] is %u\n", x, array[x] );
return 0;
}