Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags


What is crealf in C?

Hassaan Waqar

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:

How does crealf work?


The crealf function is defined as follows:

float crealf(float complex z);

It takes in a single parameter of type float complex.


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 function

int main(){

  float complex z = 2.0 + 7.0*I; // assign value to variable
  printf("The real part is %f", crealf(z));
  return 0;

crealf, creal and creall are similar functions.

  • crealf takes a float complex number and returns itsfloat real
  • creal takes a double complex number and returns its double 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