Mon May 22 07:41:00 UTC 2023 inscode

上级 99778300
#include <stdio.h>
#define ROW 3
#define COL 4
#define N 10
int main()
int main(int argc, char** argv)
{
int a[10] = {0,1,2,3,4,5,6,7,8,9}; // 声明并初始化整型数组a
int temp = 0; // 声明整型变量temp并初始化为0
int *p = a; // 声明指针变量p并初始化为数组a的首地址
printf("p的初始值为%p, *p值为%d\n", p, *p); // 输出p的初始值和*p的值
temp = *p++; // 将*p的值赋给temp,然后p指向下一个元素
printf("*p的值为%d, 运算后p的值为%p, *p的值为%d\n\n", temp, p, *p); // 输出运算后的结果
printf("p的初始值为%p, *p值为%d\n", p, *p); // 输出p的初始值和*p的值
temp = *(p++); // 将*p的值赋给temp,然后p指向下一个元素
printf("*(p++)的值为%d, 运算后p的值为%p, *p的值为%d\n\n", temp, p, *p); // 输出运算后的结果
printf("p的初始值为%p, *p值为%d\n", p, *p); // 输出p的初始值和*p的值
temp = (*p)++; // 将*p的值赋给temp,然后*p的值加1
printf("(*p)的值为%d, 运算后p的值为%p, *p的值为%d\n\n", temp, p, *p); // 输出运算后的结果
printf("p的初始值为%p, *p值为%d\n", p, *p); // 输出p的初始值和*p的值
temp = *p; // 将*p的值赋给temp
p++; // p指向下一个元素
printf("*p++的值为%d, 运算后p的值为%p, *p的值为%d\n\n", temp, p, *p); // 输出运算后的结果
printf("p的初始值为%p, *p值为%d\n", p, *p); // 输出p的初始值和*p的值
temp = *(p); // 将*p的值赋给temp
p++; // p指向下一个元素
printf("*(p)的值为%d, 运算后p的值为%p, *p的值为%d\n\n", temp, p, *p); // 输出运算后的结果
printf("p的初始值为%p, *p值为%d\n", p, *p); // 输出p的初始值和*p的值
temp = *p; // 将*p的值赋给temp
printf("*p的值为%d, 运算后p的值为%p, *p的值为%d\n\n", temp, p+1, *(p+1)); // 输出运算后的结果
printf("p的初始值为%p, *p值为%d\n", p, *p); // 输出p的初始值和*p的值
temp = (*p); // 将*p的值赋给temp
printf("(*p)的值为%d, 运算后p的值为%p, *p的值为%d\n\n", temp, p, *p+1); // 输出运算后的结果
int i, j;
int mat[ROW][COL] = {
{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12}
};
// 使用循环嵌套输出二维数组 mat 的每个元素
for (i = 0; i < ROW; i++) // 遍历行
{
for (j = 0; j < COL; j++) // 遍历列
printf("%d\t", *(*mat + i * COL + j)); // 输出第 i 行,第 j 列的元素
printf("\n"); // 每输出一行,就换行
}
return 0;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册