General Built-in Functions
Discover how to use common C++ built-in functions to handle arrays and characters efficiently. Learn to reverse arrays, round numbers, sort elements, and change character case, enhancing your coding skills with practical examples.
We'll cover the following...
Library functions
C++ libraries provide certain utility functions that make it easier for programmers to perform routine tasks, like pow() and sqrt(). The commonly used other such functions are sizeof(), round(), reverse(), and sort().
Note: We have to include respective header files that allow the use of these functions in the program.
Let’s explore some commonly used built-in functions.
Reverse order
The reverse() function is used to access the elements of the array in reverse order. The result of this function is stored in the array itself. The syntax of calling this function is as follows:
reverse(array_name, array_name + array_length)
The beginning of the array can be accessed by simply using the array name, and in a similar fashion, the end of the array can be accessed by writing the name plus its length.
The following code will demonstrate how this function works:
In the program above:
- An array variable
arr[]is declared, and{0,1,2,3,4,5}is