O'Reilly logo

Just Enough C/C++ Programming by Guy W. Lecky-Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Defining Functions

A key part of C programming, as in many other languages, is the ability to break up a program into smaller chunks that can be called, usually by name, from within other code blocks. In C, this is done using functions.

Functions are pieces of named code—code blocks that are self-contained, called by name, can take parameters, and provide return values. Recall the first-ever function declaration you saw:

<return type> main ( [argument list] )

This generic definition is incomplete because it does not contain any C code to be executed when the function is called. To expand upon this declaration, you can add a function body to it, which will actually do some work. The general form for declaring an entire function is as follows: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required