01 #include <stdio.h>
02
03 int main() {
04 int a[5] = {0}; // 定义数组并初始化
05 int *p_max = NULL; // 定义指针变量
06
07 // 输入数组元素
08 printf(“请输入5个整数:\n”);
09 for (int i = 0; i < 5; i++) {
10 scanf("%d", &a[i]);
11 }
12
13 // 找最大值的地址
14 p_max = &a[0]; // 先让p_max指向第一个元素
15 for (int i = 1; i < 5; i++) {
16 if (a[i] > *p_max) {
17 p_max = &a[i]; // 更新最大值地址
18 }
19 }
20
21 // 输出最大值
22 printf(“最大值是:%d\n”, *p_max);
23
24 return 0;
25 }
int main() {
unsigned int data = 0x11223344;
unsigned short *q = NULL;
unsigned short t1 = 0;
unsigned short t2 = 0;
// (1) q保存data的地址
q = (unsigned short *)&data;
// (2) 读取低2字节赋值给t1,高2字节赋值给t2
t1 = *(q); // 低2字节
t2 = *(q + 1); // 高2字节
// (3) 输出t1和t2的和与差
printf("t1 = 0x%04x\n", t1);
printf("t2 = 0x%04x\n", t2);
printf("t1 + t2 = 0x%04x\n", t1 + t2);
printf("t1 - t2 = 0x%04x\n", t1 - t2);
return 0;
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17