<29> "Mastering" #if-#else conditional compilation Instructions +

Source: Internet
Author: User

"Mastering" #if-#else conditional compilation directives

#include <stdio.h>#defineScore 99intMainintargcConst Char*argv[]) {       //Traditional Way//int score =;//    //determine which grade the score belongs to//if (score<60) {//printf ("e\n");//}else if (score<=69) {//printf ("d\n");//}else if (score<=79) {//printf ("c\n");//}else if (score<=89) {//printf ("b\n");//}else{//printf ("a\n");//    }     #ifScore < 60printf ("e\n");#elifScore <= 69printf ("d\n");#elifScore <= 79printf ("c\n");#elifScore <= 89printf ("b\n");#elseprintf ("a\n");#endif        return 0;}
Summary: Comments are not compiled, conditional compilation is partially compiled

"Mastering" #ifdef conditional compilation Instructions

conditional Compilation Directives      1 #if  #elif  #else  #endif     2) #ifdef  
#include <stdio.h>#defineDEBUG1 1#defineDEBUG2 0intMainintargcConst Char*argv[]) {        intA =0; //ifdef detect if a macro is defined#ifdef DEBUG//The DEBUG system already defines the macro.A =Ten; #else a=10000; #endifprintf ("%d\n", a); //Ifndef detect if macros are defined ifndef if not defined#ifndef DEBUG2 a= -; #elsea= -1; #endifprintf ("%d\n", a); return 0;}
Ten-1

<29> "Mastering" #if-#else conditional compilation Instructions +

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.