ch2-Function precedence

Chapter_2     Exercise_2-10 Arguments_precedence     Chapter_3







funp.c     K&R, p. 53         download


#include <stdio.h> // for printf()

// function call precedence

int f(int *x);
int g(int *x);

int main()
{
int x = 0;

x = f(&x) + g(&x);

printf("x = %d\n", x);

return 0;
}

int f(int *x)
{
printf("f(): x = %d\n", *x);
(*x)++;
printf("f(): x = %d\n", *x);

return *x;
}

int g(int *x)
{
printf("g(): x = %d\n", *x);
(*x)--;
printf("g(): x = %d\n", *x);

return *x;
}

/*
gcc funp.c -o funp
./funp
f(): x = 0 // initial value
f(): x = 1 // after incrementation
g(): x = 1 // after f()
g(): x = 0 // after decrementation
x = 1 // 1 + 0
*/









Chapter_2     Exercise_2-10 BACK_TO_TOP Arguments_precedence     Chapter_3



Comments

Popular posts from this blog

Contents

Blogger Page Margins in Contempo