C++ <complex> - real() Function
The C++ <complex> real() function returns the real part of a complex number. The additional overloads is added in C++11 to provide the arguments of any fundamental arithmetic type. In this case, the function assumes the value has a zero imaginary component, and thus simply returns z converted to the proper type.
Syntax
template<class T> T real (const complex<T>& z);
template<class T> T real (const complex<T>& z); //additional overloads double real (ArithmeticType z);
Parameters
z |
Specify the complex number. |
Return Value
Returns the real part of the complex number.
Example:
The example below shows the usage of real() function.
#include <iostream> #include <complex> using namespace std; int main (){ complex<int> z (5, 10); //display the real part of //the complex number cout<<"Real part of z: "<< real(z)<<"\n"; return 0; }
The output of the above code will be:
Real part of z: 5
❮ C++ <complex> Library