返回:贺老师课程教学链接
请写出下面程序的运行结果或说明其功能,通过运行程序进行对照
(1)
#include <stdio.h>
#define DEBUG
int main()
{
#ifdef DEBUG
printf("Debugging\n");
#else
printf("Not debugging\n");
#endif
printf("Running\n");
return 0;
}
(2)
#include <stdio.h>
#define DEBUG 0
int main()
{
#ifdef DEBUG
printf("Debugging\n");
#else
printf("Not debugging\n");
#endif
printf("Running\n");
return 0;
}
(3)
#include <stdio.h>
#define TWO
int main()
{
#ifdef ONE
printf("1\n");
#elif defined TWO
printf("2\n");
#else
printf("3\n");
#endif
return 0;
}
(4)
#include <stdio.h>
#include <malloc.h>
#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 <stdio.h>
#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;
}