12.4. Declaring and Defining Nested Functions

If you are defining a function at the

Example 12-2. simple nested function

#include <stdio.h>

int
main()
{
  int swap (int *a, int *b)
    {
      int c;

      c = *a;
      *a = *b;
      *b = c;

      return 0;
    }

  int first = 12, second = 34;

  printf("f is %d and s is %d\n", first, second);

  swap(&first, &second);

  printf("f is %d and s is %d\n", first, second);

  return 0;
}
     
You don't have to declare nested functions like you do normal functions however you can if you like. The only reason for doing so would be for the sake of readability, you might like the function definition to appear near where it is used. It's up to you, but if you do decide to declare you nested function you must explicitly declare it as auto.