What is creal in C?

The creal 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 double. The function takes in a single parameter: a double complex number.

A complex number has a real and an imaginary part.

The illustration below shows how creal works:

How does creal work?

Declaration

The creal function is defined as follows:

double creal(double complex z);

It takes in a single parameter of type double complex.

Example

The following code snippet shows how we can use the creal 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 creal function
int main(){
double complex z = 1.0 + 3.0*I; // assign value to variable
printf("The real part is %f", creal(z));
return 0;
}

creal, crealf and creall are similar functions.

  • creal takes a double complex number and returns its double real
  • crealf takes a float complex number and returns itsfloat real
  • creall takes a long double complex number and returns its long double real

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved