Functions
A function in C can perform a particular task, and supports the concept of modular programming design techniques.
The main body of a C program, identified by the keyword main, and enclosed by the left and right braces is a function.
It is called by the operating system when the program is loaded, and when terminated, returns to the operating system.
Functions have a basic structure. Their format is:
return_ data_type function name (arguments, arguments)
data _type _declarations of arguments;
{
function body
}
It is worth noting that a return data type is assumed to be of type int unless otherwise specified.
This permits type checking by utilizing function prototypes to inform the compiler of the type and number of parameters a function accepts. When calling a function, this information is used to perform the type and parameter checking.
To call a function, it is only necessary to write its name. The code associated with the function is executed at this point in the program. When the function terminates, execution begins with the statement which follows the function name.
Constructors
Objects generally need to initialize variables or assign dynamic memory during their process of creation to become totally operative and to avoid returning unexpected values during their execution.
A class can include a special function: a constructor,
which can be declared by naming a member function with the same name as the class. This constructor function
will be called automatically when a new instance of the class is created (when declaring a new object or allocating an object of that class) and only then.