Function Calls

Content

This is just a simple warm up:

Example: Local Variables

int printf(const char *, ...);       // pre-declaration of function

void
foo()
{
    int a, b;

    printf("in foo(): a=%d, b=%d\n", a, b);
}

void
dummy()
{
    int a = 42, b = 666;;
    printf("in dummy(): a=%d, b=%d\n", a, b);
}

int
main()
{
    dummy();
    foo();
}

Example: Recursive Function calls

int printf(const char *, ...);       // pre-declaration of function

unsigned int
factorial(unsigned int n)
{
    printf("&n = %p\n", &n);
    if (n>1) {
        return n*factorial(n-1);
    } else {
        return 1;
    }
}

int
main()
{
    printf("%u\n", factorial(4));
}