# if # 0 in the C language

Source: Internet
Author: User

There are conditional compilation directives in the C language, which are common:

#define Defining macros
#undef to cancel a defined macro
#if if the given condition is true, compile the following code
#ifdef If the macro is already defined, compile the following code
#ifndef if the macro is not defined, compile the following code
#elif if the previous # if given condition is not true and the current condition is true, then compiling the following code is actually the shorthand for the else if
#endif end an # if ... #else条件编译块
#error stop compiling and display an error message

#if 0 .... #endif example

#include <stdio.h>int main () {#if 0printf ("This is never here!\n"); #endifprintf ("#if ... #endif statements are never executed! \ n "); return 0;}

  

When it comes to C-language projects, someone might notice that there is a statement like # 0 in it, since the statement inside will never be executed, why leave this code behind?

Look at the following example:

#include <stdio.h>int main{/*  int a=1;     /*int b=2;*/  int c=3;      */return 0;  }

This code will be compiled with an error, because/*//with the nearest match, so an error occurred. Use # if 0 ... #endif can be used to avoid this error while leaving the code temporarily unused, but potentially valuable.

# if # 0 in the C language

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.