Changing Array Elements in Functions - C Function

C examples for Function:Function Parameter

Description

Changing Array Elements in Functions

Demo Code

#include <stdio.h>

void multiplyBy2 (float array[], int n){
    for (int i = 0; i < n; ++i )
        array[i] *= 2;//from   w w  w.  jav  a2s  .com
}

int main (void)
{
    float floatVals[4] = { 1.2f, -3.7f, 6.2f, 8.55f };

    multiplyBy2 (floatVals, 4);

    for (int i = 0; i < 4; ++i )
        printf ("%.2f   ", floatVals[i]);

    return 0;
}

Related Tutorials