字符串函数以及宏定义
2022-11-13 11:41 钟铧若岩 阅读(46) 评论(0) 编辑 收藏 举报最小值、以及平方的宏定义实现,注意()的使用
1 #include <stdio.h> 2 #include <string.h> 3 4 #define MIN(a,b) (a)<(b)?(a):(b) 5 #define SQRT(a) (a)*(a) 6 7 int main(int argc, char **argv) { 8 printf("Hello, World!\n"); 9 10 int a = 10; 11 int b = 20; 12 13 int min = MIN(a,b); 14 15 printf("min = %d\n",min); 16 17 int sqrt = SQRT(a); 18 printf("sqrt = %d\n",sqrt); 19 20 char *c = "abc"; 21 printf("c = %s\n",c); 22 23 char *d; 24 memcpy(d,c,2); 25 printf("d = %s\n",d); 26 27 return 0; 28 29 }