《C语言及程序设计》程序阅读——条件编译

返回:贺老师课程教学链接

请写出下面程序的运行结果或说明其功能,通过运行程序进行对照


(1)

#include 
#define DEBUG
int main()
{
#ifdef DEBUG
    printf("Debugging\n");
#else
    printf("Not debugging\n");
#endif
    printf("Running\n");
    return 0;
}

(2)

#include 
#define DEBUG 0
int main()
{
#ifdef DEBUG
    printf("Debugging\n");
#else
    printf("Not debugging\n");
#endif
    printf("Running\n");
    return 0;
}

(3)

#include 
#define TWO
int main()
{
   #ifdef ONE
          printf("1\n");
   #elif defined TWO
          printf("2\n");
   #else
          printf("3\n");
   #endif
   return 0;
}

(4)

#include 
#include 
#define NUM ok
int main(void)
{
    struct stu
    {
        int num;
        char *name;
        char sex;
        float score;
    } *ps;
    ps=(struct stu*)malloc(sizeof(struct stu));
    ps->num=102;
    ps->name="Zhang ping";
    ps->sex='M';
    ps->score=62.5;
#ifdef NUM
    printf("Number=%d\nScore=%f\n",ps->num,ps->score);
#else
    printf("Name=%s\nSex=%c\n",ps->name,ps->sex);
#endif
    free(ps);
    return 0;
}

(5)

#include 
#define LETTER 1
int main( )
{
    int i=0;
    static char str[ ]= { "Turbo C Program"};
    char c;
    while ((c=str[i]) != '\0')
    {
        i++;
# if LETTER
        if (c>='a' && c<='z') c=c-32;
# else
        if (c>='A' && c<='Z') c=c+32;
# endif
        printf("%c",c);
    }
    return 0;
}

你可能感兴趣的:(《C语言及程序设计》程序阅读——条件编译)