Array element as function parameter

Hi all -
I'm learning C and wanted to pose a question.  Can you pass an array element to another function?   For instance I'm in a 'FOR Loop' and generating the array with random numbers.   I would like to perform different calculations on these elements as they generate.  Can I pass the element value to another function which would perform the calculations?   Or should I save that element to a variable and then calculate returning and re-assigning the variable value back to the array element?   Thanks for the assist!
Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
Yes, sure you can pass arrays in C.

http://www-ee.eng.hawaii.edu/~tep/EE160/Book/chap7/section2.1.2.html
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
you also can pass single array elements:
``````void f(int i)
{
...
}

void g()
{
int arr[10] = { 0, 1, 2, 3, 4, 5, 6, 7 ,8 , 9 };
f(arr[5]);
}
``````

the integer at arr[5] was passed 'by value' to function f. 'by value' means, the function uses a copy of the integer element.

Sara
0
Commented:
void sum10(int *pv) {

*pv = *pv + 10;

}

void main()
{
int v[] = { 0, 1, 2, 3, 4};
for(int x=0;x<5;x++)
{
printf("Before v[%d]=%d",x,  v[x] );
sum10(&v[x]);
printf(" After v[%d]=%d\n",x,v[x]);
}
}
/* Results:
Before v[0] = 0 After v[0] = 10
Before v[1] = 1 After v[1] = 11
.
.
.

*/
0