arg_passing.c

DownloadView Raw

/**
 * arg_passing.c
 *
 * Demonstrates passing arguments by value and also simulates passing by
 * reference using pointers.
 *
 * Compile:  Using Linux and gcc
 *           gcc -g -Wall -o arg_example1 arg_example1.c
 * Run:      ./arg_passing
 */

#include <stdio.h>

void our_func1(int x)
{
    x = 24;
    printf("the address of x is: %p\n", &x);
}

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


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

    return 0;
}