Home >Backend Development >C++ >In C language, what does conditional compilation mean?
In the C programming language, there are several instructions that control the selective compilation of program code. They are as follows −
# The general form of if is as follows −
#if constant_expression statement sequence #endif
#else works similarly to the C keyword else.
#elif means "else if" and establishes an if else-if compilation chain.
Among other things, #if provides an alternative to "commenting out" code.
For example,
#if 0 printf("#d", total); #endif
Here, the compiler will ignore printf("#d", total);
#ifdef and #ifndef
#ifdef means "if defined" and ends with #endif.
#ifdef means "if not defined".
#undef
#undef deletes a previously defined definition.
#line
#line changes the contents of __LINE__, which contains the line number of the currently compiled code, and __FILE__, which is a source file containing the source file being compiled A string of names. Both of these are identifiers predefined in the compiler.
#pragma
#The pragma directive is an implementation-defined directive that allows various directives to be provided to the compiler.
The following is a C programExample demonstrating #ifdef, #ifndef, #else and #endif-
Live Demo
# include <stdio.h> # define a 10 void main(){ #ifdef a printf("</p><p> Hello I am here.."); #endif #ifndef a printf("</p><p> Not defined "); #else printf("</p><p> R u There "); #endif }
When the above program is executed, it produces the following results −
Hello I am here.. R u There
The above is the detailed content of In C language, what does conditional compilation mean?. For more information, please follow other related articles on the PHP Chinese website!