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

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 30-Jul-2019

692 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements