_Imaginary Optional pure imaginary types

_Imaginary Optional pure imaginary types

C99's optional _Imaginary is often unsupported. Portable code uses double _Complex, checks implementation macros, and provides a complex fallback.

CategoryType specifiers
KindKeyword / Statement
C standardC99

📝 Syntax

double _Imaginary iz = 4.0 * I;  /* Supported by few implementations */

▶ Example

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

Output:

complex fallback = 4
⚠️ Warning _Imaginary is optional. The example uses it when __STDC_IEC_559_COMPLEX__ and _Imaginary_I are available, otherwise falling back to double _Complex. The listed complex fallback = 4 output is GCC 10.2's default branch because it lacks _Imaginary support.

📚 Related Tutorials

❓ FAQ

QWhat is the difference between _Imaginary and _Complex?
A_Imaginary denotes a pure imaginary type, while _Complex denotes a complex type with both real and imaginary parts. For everyday complex arithmetic, _Complex is generally used because it is more widely supported.
QWhy does the _Imaginary example run _Complex fallback code by default?
ACommon implementations, including GCC, do not provide pure imaginary types, so using _Imaginary unconditionally would fail to compile. Conditional compilation retains the demonstration for supporting platforms while allowing others to run the complete example.
QHow can I detect whether a compiler supports _Imaginary?
ANo single convention covers every C99 implementation. Combine its documentation with conditional checks for capability markers such as __STDC_IEC_559_COMPLEX__ and _Imaginary_I, and verify the result with the target compiler.
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%

🙏 帮我们做得更好

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

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