Function Declarations

In this section, we will understand the purpose of functions in C++.

Definition #

A function is a set of statements and operations. Like variables, functions have names. When a function is invoked or called, the sequence of statements inside it is executed.

Rules of declaration #

  • The name of the function should hold some meaning as to what it actually does.

  • A function declaration consists of a return type, a name, and a set of parameters (optional).

  • The signature of a function is its name and parameters.

  • A function can accept values, pointers, or references.

  • Functions can be static, and their return values can be const or volatile.

Below, we can see an example of the swap function:

Get hands-on with 1200+ tech skills courses.