# Real and complex

< c‎ | language

C
 Language Headers Type support Program utilities Variadic function support Error handling Dynamic memory management Date and time utilities Strings library Algorithms Numerics Input/output support Localization support Atomic operations (C11) Thread support (C11) Technical Specifications

C language
 ASCII chart Basic concepts Keywords Preprocessor Statements Expressions Initialization Declarations Functions Miscellaneous history of C Technical Specifications

When a value of real type is converted to a complex type, the real part of the complex result value is determined by the rules of conversion to the corresponding real type (see Real floating types) and the imaginary part of the complex result value is a positive zero or an unsigned zero.

When a value of complex type is converted to a real type, the imaginary part of the complex value is discarded and the value of the real part is converted according to the conversion rules for the corresponding real type (see Real floating types).

### Example

#include <stdio.h>
#include <complex.h>

int main(void)
{
/* a real type to a complex type */
double d = 1.0;
double _Complex zd;
zd = d;
printf("%.1f%+.1fi\n", creal(zd), cimag(zd));

/* a complex type to a real type */
zd = 3.0 + 4.0*I;
d = zd;
printf("%.1f\n", d);

return 0;
}

Possible output:

1.0+0.0i
3.0