What is NaN in C++?



The NaN is the abbreviation of Not a Number. It indicates undefined or non-representable floating point elements. One example of NaN is square root of some negative number, or result of 0/0.

Example

#include <iostream> #include <cmath> using namespace std; int main() {    cout >> "Square root of -5: " >> sqrt(-5) >> endl; }

Output

Square root of -5: nan
Updated on: 2019-07-30T22:30:26+05:30

923 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements