目录
- 题一:(简单)
- 题二:
- 题三:
- 题四
- 题五:
- 题六:
- 题七:
题一:(简单)
//输出的结果为?
int main()
{
int a[5] = { 1, 2, 3, 4, 5 };
int* ptr = (int*)(&a + 1);
printf("%d,%d", *(a + 1), *(ptr - 1));
return 0;
}
🤔解释:
✅输出结果:
题二:
//x86
//假设p 的值为0x100000。 输出结果为?
struct Test
{
int Num;//4字节
char* pcName;//4字节
short sDate;//2字节
char cha[2];//2字节
short sBa[4];//8字节
}*p;
int main()
{
p = (struct Test*)0x100000;
printf("%p\n", p + 0x1);
printf("%p\n", (unsigned long)p + 0x1);
printf("%p\n", (unsigned int*)p + 0x1);
return 0;
}
🤔解释:
Tip:① 0x1是十六位进制,相当于1
Tip:
②%p
输出默认没有0x
,而是00
③%#x
可以补上0x
✅输出结果:
题三:
//输出结果为?
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);
return 0;
}
🤔解释:
大小端知识👉深度剖析数据在内存中的存储👈
✅输出结果:
题四
//输出结果为?
int main()
{
int a[3][2] = { (0, 1), (2, 3), (4, 5) };
int* p;
p = a[0];
printf("%d", p[0]);
return 0;
}
🤔解释:
Tip:逗号表达式(表达式1,表达式2),值是表达式2的值
✅输出结果:
题五:
//输出结果为?
int main()
{
int a[5][5];
int(*p)[4];
p = a;
printf("%p,%d\n", &p[4][2] - &a[4][2], &p[4][2] - &a[4][2]);
return 0;
}
🤔解释:
Tip:指针相减得到元素的个数
✅输出结果:
题六:
//输出结果为?
int main()
{
char* a[] = { "xi","yang","ding" };
char** pa = a;
pa++;
printf("%s\n", *pa);
return 0;
}
🤔解释:
Tip:对于printf()来说只要给字符串的起始地址就能打印出对应的内容
✅输出结果:
题七:
//输出结果为?
int main()
{
char *c[] = {"ENTER","NEW","POINT","FIRST"};
char**cp[] = {c+3,c+2,c+1,c};
char***cpp = cp;
printf("%s\n", **++cpp);
printf("%s\n", *--*++cpp+3);
printf("%s\n", *cpp[-2]+3);
printf("%s\n", cpp[-1][-1]+1);
return 0;
}
🤔解释:
✅输出结果: