常量 作业
#include <stdio.h>#define NL \\n
int main()
{
printf("Line1%s",NL);
printf("Line2%s",NL);
return 0;
}
输出:
error: expected expression
printf("Line1%s",NL);
^
常量-作业.c:14:12: note: expanded from macro 'NL'
#define NL \\n
^
常量-作业.c:20:22: error: expected expression
printf("Line2%s",NL);
^
常量-作业.c:14:12: note: expanded from macro 'NL'
#define NL \\n
^
2 errors generated.
问:\\不是代表\本身吗,那为什么\\n不行呢?
占位符%s有错吗? 字符串你好歹给它加个双引号 #include <stdio.h>
#define NL "\n"
int main(){
printf("Line1%s", NL);
printf("Line2%s", NL);
return 0;
} 傻眼貓咪 发表于 2022-3-19 12:15
如果想用const怎么写
Weabu 发表于 2022-3-19 14:42
如果想用const怎么写
已解决const char* NL="\n";
页:
[1]