We recommend using Visual Studio 2017

# sqrt, sqrtf, sqrtl

Visual Studio 2015

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at sqrt, sqrtf, sqrtl.

Calculates the square root.

## Syntax

```double sqrt(
double x
);
float sqrt(
float x
);  // C++ only
long double sqrt(
long double x
);  // C++ only
float sqrtf(
float x
);
long double sqrtl(
long double x
);

```

#### Parameters

`x`
Non-negative floating-point value

## Remarks

Because C++ allows overloading, you can call overloads of `sqrt` that take `float` or `long double` types. In a C program, `sqrt` always takes and returns `double`.

## Return Value

The `sqrt` functions return the square-root of `x`. By default, if `x` is negative, `sqrt` returns an indefinite NaN.

InputSEH Exception`_matherr` Exception
± QNAN,INDnone_DOMAIN
- ∞none_DOMAIN
x<0none_DOMAIN

## Requirements

`sqrt`, `sqrtf`, `sqrtl`<math.h><cmath>

For compatibility information, see Compatibility.

## Example

```// crt_sqrt.c
// This program calculates a square root.

#include <math.h>
#include <stdio.h>
#include <stdlib.h>

int main( void )
{
if( question < 0 )
printf( "Error: sqrt returns %f\n", answer );
else
printf( "The square root of %.2f is %.2f\n", question, answer );
}

```
```The square root of 45.35 is 6.73

```

## .NET Framework Equivalent

System::Math::Sqrt