Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags


What is creal in C?

Hassaan Waqar

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?


The creal function is defined as follows:

double creal(double complex z);

It takes in a single parameter of type double complex.


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




Hassaan Waqar
Copyright ©2022 Educative, Inc. All rights reserved

View all Courses

Keep Exploring