diff --git a/test/d1.c b/test/d1.c new file mode 100644 index 0000000..3977e13 --- /dev/null +++ b/test/d1.c @@ -0,0 +1,25 @@ +#include + +// 这种方式只能交换指针指向的值,不能交换指针本身,而且无法改变实参的值 +void swap(int *piA, int *piB) +{ + printf("first iA-p: %p, iB-p: %p\n iA: %d,iB: %d\n", piA, piB, *piA, *piB); + + int *piC; + piC = piA; + piA = piB; + piB = piC; + printf("after iA-p: %p, iB-p: %p\n iA: %d,iB: %d\n", piA, piB, *piA, *piB); +} + +int main() +{ + int iA = 100, iB = 200; + printf("main first iA-p: %p, iB-p: %p\n iA: %d,iB: %d\n", &iA, &iB, iA, iB); + + int *piA = &iA, *piB = &iB; + swap(piA, piB); + printf("main after iA-p: %p, iB-p: %p\n iA: %d,iB: %d\n", &iA, &iB, iA, iB); + + return 0; +} \ No newline at end of file diff --git a/test/d2.c b/test/d2.c new file mode 100644 index 0000000..966e270 --- /dev/null +++ b/test/d2.c @@ -0,0 +1,25 @@ +#include + +// 会交换实参的值 +void swap(int *piA, int *piB) +{ + // printf("first iA-p: %p, iB-p: %p\n iA: %d,iB: %d\n", piA, piB, *piA, *piB); + + int piC; + piC = *piA; + *piA = *piB; + *piB = piC; + // printf("after iA-p: %p, iB-p: %p\n iA: %d,iB: %d\n", piA, piB, *piA, *piB); +} + +int main() +{ + int iA = 100, iB = 200; + printf("first iA-p: %p, iB-p: %p\n iA: %d,iB: %d\n", &iA, &iB, iA, iB); + + int *piA = &iA, *piB = &iB; + swap(piA, piB); + printf("after iA-p: %p, iB-p: %p\n iA: %d,iB: %d\n", &iA, &iB, iA, iB); + + return 0; +} \ No newline at end of file diff --git a/test/t1_11.c b/test/t1_11.c new file mode 100644 index 0000000..48bdda6 --- /dev/null +++ b/test/t1_11.c @@ -0,0 +1,13 @@ +#include + +#define ADD(x, y) (x + y) /*加*/ +#define SUB(x, y) (x) - (y) /*减*/ +#define MUL(x, y) (x * y) /*乘*/ + +int main() +{ + unsigned int uiA; + uiA = MUL(ADD(9, 2), SUB(6, 3)); // ((9+2)*(6)-(3)) = 63 + printf("uiA = %d\n", uiA); + return 0; +} \ No newline at end of file diff --git a/test/t1_4.c b/test/t1_4.c new file mode 100644 index 0000000..d06a21d --- /dev/null +++ b/test/t1_4.c @@ -0,0 +1,15 @@ +#include +int main() +{ + int i; + int sum = 1; + for (i = 1; i <= 10; i++) + { + sum += i; // 加完之后才判断是否为5,因此sum会加上5 + if (i == 5) + continue; + // printf("i = %d, sum=%d\n", i, sum); + } + printf("sum=%d\n", sum); + return 0; +} \ No newline at end of file diff --git a/test/t2_1_4.c b/test/t2_1_4.c new file mode 100644 index 0000000..623d508 --- /dev/null +++ b/test/t2_1_4.c @@ -0,0 +1,18 @@ +#include + +int main() +{ + unsigned int uiCount = 0; + for (; uiCount <= 10; uiCount++) + { + printf("uiCount=%u\n", uiCount); + + if (uiCount == 5) + { + break; + } + // printf("uiCount=%u\n", uiCount); + } + // printf("uiCount=%u\n", uiCount); + return 0; +} \ No newline at end of file diff --git a/test/t3_3.c b/test/t3_3.c new file mode 100644 index 0000000..75c6532 --- /dev/null +++ b/test/t3_3.c @@ -0,0 +1,17 @@ +void func(char aver[100]) +{ + char str[] = "hello world"; + char *p = str; + char n = 10; + void *p1 = malloc(100); + printf("size1=[%d]\n", sizeof(str)); + printf("size2=[%d]\n", sizeof(p)); + printf("size3=[%d]\n", sizeof(n)); + printf("size4=[%d]\n", sizeof(aver)); + printf("size5=[%d]\n", sizeof(p1)); +} +int main() +{ + char str[100]; + func(str); +} \ No newline at end of file