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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.