This lesson includes an expert video walkthrough — purchase once for a full year of unlimited replays to master every key point 🎬
Built-in Functions
Knowledge Summary
Math Functions (<cmath>)
| Function | Purpose | Example |
|---|---|---|
abs(x) | Absolute value | abs(-5) -> 5 |
sqrt(x) | Square root | sqrt(16) -> 4.0 |
pow(x, y) | x raised to the power y | pow(2, 10) -> 1024.0 |
ceil(x) | Round up | ceil(3.2) -> 4 |
floor(x) | Round down | floor(3.8) -> 3 |
round(x) | Round to the nearest integer | round(3.5) -> 4 |
log(x) | Natural logarithm | log(e) -> 1.0 |
log2(x) | Base-2 logarithm | log2(8) -> 3.0 |
Algorithm Functions (<algorithm>)
| Function | Purpose |
|---|---|
sort(begin, end) | Sorts in ascending order by default |
sort(begin, end, cmp) | Custom sorting |
max(a, b) | Returns the larger value |
min(a, b) | Returns the smaller value |
swap(a, b) | Swaps two values |
reverse(begin, end) | Reverses a sequence |
find(begin, end, val) | Searches for a value |
count(begin, end, val) | Counts occurrences |
lower_bound(begin, end, val) | First position with value >= val |
upper_bound(begin, end, val) | First position with value > val |
String Functions (<string>)
| Function | Purpose |
|---|---|
s.length() / s.size() | String length |
s.substr(pos, len) | Substring |
s.find(str) | Finds a substring |
s.append(str) | Appends content |
stoi(s) | Converts a string to int |
to_string(n) | Converts a number to a string |
Character Classification Functions (<cctype>)
| Function | Purpose |
|---|---|
isdigit(c) | Whether it is a digit |
isalpha(c) | Whether it is a letter |
isupper(c) | Whether it is uppercase |
islower(c) | Whether it is lowercase |
toupper(c) | Converts to uppercase |
tolower(c) | Converts to lowercase |