出个宏定义的题目
/* Note:Your choice is C IDE */#include "stdio.h"
#define A 100
void main()
{
int i = 2, j = 3;
int max(int a,int b);
printf("i+A = %d\n",i +A);
printf("max = %d\n",max(i,j)); //A的值为什么会改变
#undef A
#define A 10
printf("i+A = %d\n",i +A);
printf("max = %d\n",max(i,j));
}
int max(int a,int b)
{
return a>b?a+A:b+A;
}
/******************************************************/
#include "stdio.h"
#define A 100
int max(int a,int b)
{
return a>b?a+A:b+A;
}
void main()
{
int i = 2, j = 3;
printf("i+A = %d\n",i +A);
printf("max = %d\n",max(i,j)); //A的值为什么没改变?
#undef A
#define A 10
printf("i+A = %d\n",i +A);
printf("max = %d\n",max(i,j));
}
自己总结的(不知道在任何情况下是不是这个样子):undef截至的宏只是对程序后面的有效,前面的无效;