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

Declaring Functions

Every function has a declaration that is designed to tell the compiler and linker how other code is allowed to interface with it. The declaration gives no information to the compiler as to what the function does or how it does it, just how it can be called.

The usual way to declare a function is to give a return type (or void if no value is to be returned), a valid function name, and a list of parameters, with their types, in parentheses. As always, when naming user-defined objects in C, the names should be:

  • Meaningful (real language, szUserName, for example).

  • Case-appropriate (not szusername).

  • Not C keywords, or similar to them, without good reason.

The main function is a good example of a function declaration:

void main () ...

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