CS 220 Parallel Computing

arg_passing.c

DownloadView Raw

/**
 * arg_passing.c
 *
 * Demonstrates passing arguments by value and by reference.
 */
#include <stdio.h>

void our_func(int x)
{
    x = 24;
}

void our_func2(int * x_p)
{
    *x_p = 24;
    printf("the address of x_p is: %p\n", x_p);
}


int main(void)
{
    int a = 9;
    our_func(a);
    printf("a is: %d\n", a);
    our_func2(&a);
    printf("a is: %d\n", a);

    return 0;
}