log10() Function in C++ Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The std::log10() in C++ is a built-in function that is used to calculate the base-10 logarithm of a given number. It is defined inside <cmath> header file. In this article, we will learn about log10() in C++ and its behavior for different values.Example: C++ // C++ Program to illustrate the use of log10() #include <iostream> #include <cmath> using namespace std; int main() { cout << log10(100.00) << endl; cout << log10(1); return 0; } Output2 0log10() Syntaxstd::log10(n);Parametersn: Value whose base 10 logarithm is to be calculated. Can be of any numeric type such as int, long, float, double, etc.Return ValueThe log10() function returns different values depending on the parameter:Returns base 10 logarithm of given number, if number is greater than 1.Return negative integer, if number is in between 0 and 1 (not inclusive).Returns -inf (infinity) , if the number is 0.Returns inf (infinity) , if the number is very large.Returns NaN (Not a Number), if the number is negative.More Examples of log10()The following examples demonstrate the behaviors of std::log10() function in different scenarios.Example 1: Calculating log10() for Different Number Types C++ // C++ Program to compute log10() for different // number types #include <bits/stdc++.h> using namespace std; int main() { // Calculating log10() for different // types of numeric values cout << log10(100) << endl; cout << log10(1000.5f) << endl; cout << log10(10000.123); return 0; } Output2 3.00022 4.00001Example 2: Using log10() for Negative Numbers and Zero C++ // C++ Program to check the output of log10() // with negative numbers #include <iostream> #include <cmath> using namespace std; int main() { // log10 of a negative number cout << log10(-100.0) << endl; // log10 of a negative number cout << log10(0); return 0; } Outputnan -inf Create Quiz Comment A anmolpanxq Follow 0 Improve A anmolpanxq Follow 0 Improve Article Tags : C++ CPP-Library CPP-Functions cpp-math Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like