Puzzle P13

Three functions

Review of Call by Value

What does the following code write to the monitor?

#include <stdio.h>

void functionB( int y )  
{
  printf("    y=%d\n", y );
  y = 999;
  printf("    y=%d\n", y );
}

void functionA( int x )  
{
  printf("  x=%d\n", x );
  x = 123;
  functionB( x );
  printf("  x=%d\n", x );
}

void main ( void )
{
  int a = 77;
  printf("a=%d\n", a );
  functionA( a );
  printf("a=%d\n", a );
}

In this puzzle main() calls functionA() which calls functionB(). Of course, call by value is used for all these calls and changes made by a function to its parameter do not affect any variable in the caller.



Answer         Next Page         Previous Page Home