log() Function in C++ Last Updated : 17 Sep, 2025 Comments Improve Suggest changes 27 Likes Like Report The std::log() in C++ is a built-in function that is used to calculate the natural logarithm (base e) of a given number. The number can be of any data type i.e. int, double, float, long long. It is defined inside the <cmath> header file. C++ // C++ program to show the working of log() #include <bits/stdc++.h> using namespace std; int main() { // Return positive integer if the number is // greater than 1 cout << log(11) << endl; // Return negative integer if the number is // between 0 and 1 (not inclusive) cout << log(0.5) << endl; // Return 0 if the number is 1 cout << log(1) << endl; // Return -inf (infinity) if the number is 0 cout << log(0) << endl; // Return inf (infinity) if the number is very large cout << log(1e1000) << endl; // Return NaN (Not a Number) if the number is ngative cout << log(-11) << endl; return 0; } Output2.3979 -0.693147 0 -inf inf nan Syntaxstd::log(n);Parametersn: Value whose natural logarithm is to be found.Return ValueReturns the natural log (base e) of the value Create Quiz Comment S Striver Follow 27 Improve S Striver Follow 27 Improve Article Tags : Misc C++ STL CPP-Library 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