What is crealf in C?
The crealf function is part of the <complex.h> header file in C. It is used to return the real part of a complex number of type float. The function takes in a single parameter: a float complex number.
A complex number has a real and an imaginary part.
The illustration below shows how crealf works:
Declaration
The crealf function is defined as follows:
float crealf(float complex z);
It takes in a single parameter of type float complex.
Example
The following code snippet shows how we can use the crealf function. The code below outputs the real part of the complex number:
#include <stdio.h> // Including header file for printf function#include <complex.h> // Including header file for crealf functionint main(){float complex z = 2.0 + 7.0*I; // assign value to variableprintf("The real part is %f", crealf(z));return 0;}
crealf,crealandcreallare similar functions.
crealftakes afloatcomplex number and returns itsfloatrealcrealtakes adoublecomplex number and returns itsdoublerealcrealltakes along doublecomplex number and returns itslong doublereal
Free Resources
Copyright ©2025 Educative, Inc. All rights reserved