![]() |
In-built functions in C++ are those functions that are part of C++ standard libraries. The purpose of inbuilt functions is to provide common and essential functionality that is frequently required in the programming. In this article, we will look at some of the commonly used inbuilt functions in C++. 1. sqrt() FunctionThe sqrt() function is used to determine the square root of the value of type double. It is defined inside <cmath> header file. Syntaxsqrt (n) Parameter
Return Type
ExampleC++
Output
4.89898 2. pow() FunctionThe pow() function is used to find the value of the given number raised to some power. This function is also defined inside <cmath> header file. Syntaxdouble pow(double x, double y); Parameters
Return Type
ExampleC++
Output
9 3. sort() FunctionThe sort() function is part of STL’s <algorithm> header. It is a function template that is used to sort the random access containers such as vectors, arrays, etc. Syntaxsort (arr , arr + n, comparator) Parameters
Return Value
ExampleC++
Output
1 2 3 4 6 7 8 4. find() FunctionThe find() function is also the part of STL <algorithm> library. This function is used to find some value in the given range. It can be used with both sorted and unsorted datasets as it implements. Syntaxfind(startIterator, endIterator, key) Parameter
Return Value
ExampleC++
Output
The element found at 2 index 5. binary_search() FunctionThe binary_search() function is also used to find an element in the range but this function implements the binary search instead of the linear search as compared to the find function. It is faster than the find() function but it can only be implemented on sorted datasets with random access. It is defined inside the <algorithm> header file. Syntaxbinary_search (starting_pointer , ending_pointer , target); Parameters
Return Value
ExampleC++
Output
16 is not present 6 . max() FunctionThe std::max() function is used to compare the two numbers and find the maximum among them. It is also defined inside the <algorithm> header file. Syntaxmax (a , b) Parameters
Return Value
ExampleC++
Output
7 7 . min() FunctionThe std::min() function is used to compare the two numbers and find the minimum among them. It is also defined inside the <algorithm> header file. Syntaxmin (a , b) Parameters
Return Value
ExampleC++
Output
3 8. swap() FunctionThe std::swap() function provides the basic functionality to swap two values. It is defined inside <algorithm> header file. Syntaxswap(a , b); Parameters
Return Value
ExampleC++
Output
Before swap: a: 3 b: 4 After swap: a: 4 b: 3 9. tolower() FunctionThe tolower() function is used to convert the given alphabet character to the lowercase. It is defined inside the <cctype> header. Syntaxtolower (c); Parameters
Return Value
ExampleC++
Output
gfg 10. toupper() FunctionThe toupper() function is used to convert the given alphabet character to uppercase. It is defined inside the <cctype> header. Syntaxtoupper (c); Parameters
Return Value
ExampleC++
Output
GEEKSFORGEEKS |
Reffered: https://www.geeksforgeeks.org
C++ Programs |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |