F16 Answer


On my system, when I compile and run the program, I get:


#include <stdio.h>

void newFunction( int *p )  
{
  printf("  p=%d\n", *p ); 
}

void main ( int argc, char **argv )
{
  int a = 77 ;
  printf("a=%d\n", a ) ;
  newFunction( a ) ;
  
  system("pause") ;
}

Notes:

This is a case where the caller main() and the callee newFunction() are not properly coordinated.

main() passes the contents of the variable a (which is 77):

newFunction( a )

But newFunction(int *p) expects the address of an int variable (a pointer to an int). So when it calls

printf("  p=%d\n", *p )

it tries to go to address 77 in memory. But 77 points to a place in memory that this program does not have access to. The operating system does not let the program do this, and kills it.