What is a Function in Programming Languages? (Examples in C++)

Function is a group of statements in a program that perform a specific task. In other words; functions are blocks of codes that accomplish individual results. Every function in a program is given a specific name.

Every C++ program has at least one function called the main () function. Depending on the length and complexity of programs they are divided into one or several functions.

How many functions you create in a program is completely dependent over the programmer. On the other hand; logically functions should be set in a manner that every functions should perform a specific task.

There are two types of functions in programming languages.
a) Library functions: They are built-in functions. Like; sqrt (), strcat (), memcpy ()
b) User defined functions: They are the functions that are defined by the user.

How to define a function in C++?

The most common syntax to define functions is:

In which:
– “type” is the type of the value returned by the functions.
– “name” is the name of the functions and by which it can be called later.
– “statements” is the body of the functions.

See Also: [button link=”http://codejow.com/basic-operators-programming/” size=”default” icon=”fa-search-plus” side=”left” target=”” color=”090fb7″ textcolor=”ffffff”]Basic Operators in Programming[/button]

Program having Library Function:


Library Function Output

See Also: [button link=”http://codejow.com/php-tutorials-2-creating-first-php-project/” size=”default” icon=”fa-star” side=”left” target=”” color=”0202b7″ textcolor=”ffffff”]Creating First PHP Project[/button]

Program having User Defined Function:


User Defined Function Output



  • Leave a Reply

    %d bloggers like this: