| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
#include <stdio.h> 
 
#define r 5 
#define S(r) "2*3.14*r*r" 
#define C(r) "2*3.14*r" 
 
int main() 
{ 
    const char* NL="\n"; 
 
    printf("Line1%s",NL); 
    printf("Line2%s",NL); 
    printf("半径为%d的圆\n",r); 
    printf("面积是:%4.2f\n",S(r)); 
    printf("周长是:%4.2f\n",C(r)); 
 
    return 0; 
} 
 
输出 
常量-作业.c:26:34: warning: format specifies type 'double' but the argument has type 'char *' [-Wformat] 
    printf("面积是:%4.2f\n",S(r)); 
                    ~~~~~    ^~~~ 
                    %4.2s 
常量-作业.c:16:14: note: expanded from macro 'S' 
#define S(r) "2*3.14*r*r" 
             ^~~~~~~~~~~~ 
常量-作业.c:27:34: warning: format specifies type 'double' but the argument has type 'char *' [-Wformat] 
    printf("周长是:%4.2f\n",C(r)); 
                    ~~~~~    ^~~~ 
                    %4.2s 
常量-作业.c:17:14: note: expanded from macro 'C' 
#define C(r) "2*3.14*r" 
             ^~~~~~~~~~ 
2 warnings generated. 
 
该怎么改
 
- #include <stdio.h>
 
  
- #define r 5
 
 - #define S(r) 2*3.14*r*r           // 把双引号去掉
 
 - #define C(r) 2*3.14*r            // 把双引号去掉
 
  
- int main()
 
 - {
 
 -     const char* NL="\n";
 
  
-     printf("Line1%s",NL);
 
 -     printf("Line2%s",NL);
 
 -     printf("半径为%d的圆\n",r);
 
 -     printf("面积是:%4.2f\n",S(r));
 
 -     printf("周长是:%4.2f\n",C(r));
 
  
-     return 0;
 
 - }
 
  复制代码 
 
 
 |   
 
 
 
 |