CHAPTER 7

image

Functions

In this chapter, we will explain the following:

  • Why functions are important in programming
  • How to write functions
  • What happens when a function is called
  • Where functions are placed in a program
  • Some important concepts relating to functions using several examples

7.1 About Functions

So far, all our programs have consisted of a single function called main. However, we have made use of predefined C functions such as printf, scanf, strcpy, and fopen. When we run a program, it starts executing with the first statement in main and ends when it reaches the last statement.

As we have seen, it is possible to write reasonably useful ...

Get Learn to Program with C now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.