1 #include <stdio.h>
2 #include <string.h>
3 #include <math.h>
4 #define PIN1 char* //简单的字符串替换(宏替换) PIN1 替换 char*
5 typedef char* PIN2; //对类型说明符重新命名 char* 用PIN2 表示
6
7 #define A(x) x;x;x;x;x;x;x;x;x;x; //输出 0~999 的数字
8
9 #define MAX(a,b) (a>b)?a:b //带参数宏定义 MAX为宏名 (a,b) 为参数表 他们之间不能有空格
10
11 #define STR(s1 , s2 , s3 ,sum) strcat(strcat(strcat(sum,s1),s2),s3) //strcat是将后面一个字符串复制到前一个字符串的后面
12
13 #define CORRECT "abc"
14 int main3()
15 {
16 #if( 0 )
17 PIN1 x,y; //定义define后 char *x , y; 指针为4个字节
18 PIN2 a,b; //定义typedef后 char *x , *y;
19
20 printf("By #define : %d %d \n \n",sizeof(x),sizeof(y));
21 printf("By #typedef : %d %d \n \n",sizeof(a),sizeof(b));
22 #endif
23
24 #if( 0 )
25 int n = 0;
26 A(A(A(printf("%4d",n++))));
27 if(n % 10 == 0) printf("\n");
28 #endif
29
30 #if( 0 )
31 int x, y, max;
32 printf("input two numbers:");
33 scanf("%d %d",&x,&y);
34 max = MAX(x,y);
35 printf("max = %d\n",max);
36 #endif
37
38 #if( 0 )
39 char str1[] = "I", str2[] = "love" , str3[] = "you" , str[40] = "";
40 STR(str1,str2,str3,str);
41 printf("\n\tstr1 = %s\n\tstr2 = %s\n\tstr3 = %s\n\tstr = %s",str1,str2,str3,str);
42 #endif
43
44 #if( 0 )
45
46 char str[40];
47 int strcmp(char *str1, char *str2);
48 scanf("%s",str);
49 #ifndef CORRECT //如果未声明CORRECT 就往下执行定义
50 #define CORRECT "abc"
51 #endif
52 if(strcmp(str,CORRECT) == 0)
53 {
54
55 printf("you're right");
56 }
57 else
58 {
59 printf("error");
60 }
61
62 #endif
63
64
65 return 0;
66 }