下面提到的程序是开关盒的基本形式。我正在尝试在输出中打印宏变量。有关更多详细信息,请参见输出。它不打印宏变量。
开关盒
#include<stdio.h>
#define a 4
#define d 5
int main()
{
int x = 10;
switch (x)
{
case a: printf("Number is 40");
break;
case d: printf("Number is 50");
break;
default: printf("Default case");
break;
}
}
期望:数是40
实际:默认情况
请参考第1点和第2点。
#include<stdio.h>
#define a 4
#define d 5
int main()
{
int x = 4; //(Point1)Here I'm declared the x value as 4 which is equal to the above defined one of the macros. Hence the output has printed the expected value as said by @ed heal.
switch (x)
{
case a: printf("Number is 40"); //(Point 2)User can be expect anything as dummy output.
break;
case d: printf("Number is 50");
break;
default: printf("Default case");
break;
}
}
您将x
设置为10。将x
设置为10,并且a
和b
均不等于10,因此使用默认的case语句。
请参考第1点和第2点。
#include<stdio.h>
#define a 4
#define d 5
int main()
{
int x = 4; //(Point1)Here I'm declared the x value as 4 which is equal to the above defined one of the macros. Hence the output has printed the expected value as said by @ed heal.
switch (x)
{
case a: printf("Number is 40"); //(Point 2)User can be expect anything as dummy output.
break;
case d: printf("Number is 50");
break;
default: printf("Default case");
break;
}
}