_Complex C99 complex types

_Complex C99 complex types

C99's _Complex supports float, double, and long double real/imaginary parts. complex.h provides I, creal, and cimag; support is optional; check macros.

CategoryType specifiers
KindKeyword / Statement
C standardC99

📝 Syntax

double _Complex z = 3.0 + 4.0 * I;

▶ Example

Edit the C code below and click Run; the server compiles and executes it:

Output:

real = 3, imaginary = 4
ℹ️ Info The example constructs a complex value and reads its real and imaginary parts, producing 3 and 4 with GCC 10.2. Not every implementation supports complex arithmetic; check the target's linking requirements when using other mathematical library functions.

📚 Related Tutorials

❓ FAQ

QWhat is I in complex.h?
AI is a macro defined by complex.h that represents a complex constant expression usable to construct the imaginary unit. Here, 4.0 * I creates a complex value with imaginary part 4; I is not a variable holding the letter I.
QHow are the real and imaginary parts of double _Complex read?
AAfter including complex.h, creal returns the real part and cimag the imaginary part of a double complex value. For float and long double variants, use crealf and cimagf, or creall and cimagl, respectively.
QMust every C99 compiler support _Complex?
ANo. A C99 freestanding implementation may omit complex types, so other C99 features do not prove support. C11 provides __STDC_NO_COMPLEX__ for an implementation that declares no support; C99 has no such macro, so consult the implementation documentation or perform a compile test.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏