-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice
More file actions
226 lines (212 loc) · 4.53 KB
/
Copy pathpractice
File metadata and controls
226 lines (212 loc) · 4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
// #include <stdio.h>
// int i;
// int main()
// {
// i--; //-1
// if (i > sizeof(i)) //sizeof这个操作符,算出来的结果类型是unsigned int
// {
// printf("> \n"); //-1被解读成一个unsigned int型,是一个非常大的整数·
// }
// else
// {
// printf("< \n");
// }
// //打印">"
// return 0;
// }
//求Sn=a+aa+aaa+aaaa+aaaaa的和
// #include <stdio.h>
// int main()
// {
// int a = 0;
// int n = 0;
// scanf("%d %d", &a, &n);
// int i = 0;
// int sum = 0;
// int ret = 0;
// for (i = 0; i < n; i++)
// {
// ret = ret * 10 + a;
// sum += ret;
// }
// printf("%d", sum);
// return 0;
// }
//写一个函数打印arr数组的内容,不使用数组下标,使用指针
// #include <stdio.h>
// int main()
// {
// int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
// int *p = arr;
// int i = 0;
// int sz = sizeof(arr) / sizeof arr[0];
// for (i = 0; i < sz; i++)
// {
// printf("%d", *(p+i));
// }
// return 0;
// }
//求出0~100000之间所有的水仙花数(n位数,各位数的n次方和等于该数本身)
// #include <stdio.h>
// #include <math.h>
// int main()
// {
// int i;
// for (i = 0; i <= 100000; i++)
// {
// //计算i的位数
// int tmp = i;
// int n = 1;
// while (tmp / 10)
// {
// n++;
// tmp /= 10;
// }
// //计算每一位数的n次方和
// tmp = i;
// int sum;
// while (tmp)
// {
// sum += pow(tmp % 10, n);
// tmp /= 10;
// }
// //判断
// if (sum == i)
// {
// printf("%d ", i);
// }
// }
// return 0;
// }
// #include <stdio.h>
// struct stu
// {
// int num;
// char name[10];
// int age;
// };
// void func(struct stu *p)
// {
// printf("%s\n", (*p).name); //打印"wang"
// }
// int main()
// {
// struct stu students[3] =
// {
// {9801, "zhang", 30},
// {8787, "wang", 23},
// {8976, "chen", 43}};
// func(students + 1);
// return 0;
// }
//写一个函数,逆序输出一个字符串的内容
// #include <stdio.h>
// #include <assert.h>
// #include <string.h>
// void reverse(char *str)
// {
// assert(str);
// int len = strlen(str);
// char *left = str;
// char *right = str + len - 1;
// while (left < right)
// {
// char tmp = *left;
// *left = *right;
// *right = tmp;
// left++;
// right--;
// }
// }
// int main()
// {
// char arr[] = "abcdefg";
// reverse(arr);
// printf("%s", arr);
// return 0;
// }
// #include <stdio.h>
// struct test
// {
// int Num;
// char *pcName;
// short sDate;
// char cha[2];
// short sBa[4];
// } * p;
// //已知结构体的大小为20字节
// //假设p的值为0x100000
// int main()
// {
// printf("%p\n", p + 0x1); //0x100014 --> 跳过20个字节
// printf("%p\n", (unsigned long)p + 0x1); //0x100001
// printf("%p\n", (unsigned int *)p + 0x1); //0x100004
// return 0;
// }
// #include <stdio.h>
// int main()
// {
// int a[4] = {1, 2, 3, 4};
// int *ptr1 = (int *)(&a + 1);
// int *ptr2 = (int *)((int)a + 1);
// printf("%x,%x ", ptr1[-1], *ptr2);
// //0x00000004,0x02000000 (小端存储)
// return 0;
// }
// #include <stdio.h>
// int main()
// {
// int a[3][2] = {(0, 1), (2, 3), (4, 5)}; //数组元素为逗号表达式,其值为1,3,5
// /*
// 1 3
// 5 0
// 0 0
// */
// int *p;
// p = a[0]; //1的地址
// printf("%d", p[0]); //p[0] == *(p+0)
// // 1
// return 0;
// }
// #include <stdio.h>
// int main()
// {
// int a[5][5];
// int(*p)[4];
// p = a; //int(*)[5]
// //+1走的长度不一样
// printf("%p,%d", &p[4][2] - &a[4][2], &p[4][2] - &a[4][2]); //p[4][2] == *(*(p+4)+2)
// //FFFFFFFC,-4
// return 0;
// }
// #include <stdio.h>
// int main()
// {
// int a[2][5] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
// int *ptr1 = (int *)(&a + 1);
// int *ptr2 = (int *)(*(a + 1));
// printf("%d, %d", *(ptr1 - 1), *(ptr2 - 1));
// //10 5
// return 0;
// }
// #include <stdio.h>
// int main()
// {
// char *a[] = {"work", "at", "alibaba"};
// char **pa = a;
// pa++;
// printf("%s ", *pa); // at
// return 0;
// }
// #include <stdio.h>
// int main()
// {
// char *c[] = {"enter", "new", "point", "first"};
// char **cp[] = {(c + 3), (c + 2), (c + 1), c};
// char ***cpp = cp;
// printf("%s\n", **++cpp); //point
// printf("%s\n", *--*++cpp + 3); //er
// printf("%s\n", *cpp[-2] + 3); // **(cpp-2)+3 st
// printf("%s\n", cpp[-1][-1] + 1); //*(*(cpp-1)-1)+1 ew
// return 0;
// }