E17 Answer


Answer 1: The program compiles and runs.

Answer 2: It produces the correct result:

scope m: x=4

However, see the comments.


#include <stdio.h>

int dum( int x )
{
  x -= 1 ;
  x = dee(x);
  return x;
}

int dee( int a )
{
  if ( a > 10 )
    a = dum(a);
  else
    a -= 2 ;

  return a;
}

int main ( void )
{
  int x;
  
  x = dum(7);
  printf("scope m: x=%d\n", x);

  system("pause") ;
  return 0 ;
}

Comments: The function dum() uses a function dee() that has not been declared yet. The compiler assumes that dee() is a function that returns int. This is indeed what it is, and the assumption causes no problems. Later on, dee()is defined and matches what the compiler assumed.

The program compiles without error or warning and runs correctly. But it is not wise to rely on implicit declarations. The program could be improved by inserting function prototypes that make explicit the form of each function.

Prototypes are used, since each function calls the other and there is no arrangement in which all identifiers are declared before use.

Answer 3: See below.


#include <stdio.h>

/* Only one prototype is needed, but it does not hurt */
/* to have both, and might be useful in the future. */
int dum( int x );
int dee( int x );

int dum( int x )
{
  x -= 1 ;
  x = dee(x);
  return x;
}

int dee( int a )
{
  if ( a > 10 )
    a = dum(a);
  else
    a -= 2 ;

  return a;
}

int main ( void )
{
  int x;
  
  x = dum(7);
  printf("scope m: x=%d\n", x);

  system("pause") ;
  return 0 ;
}