//笔试1
#include <stdio.h>
#include <windows.h>
int main()
{
int a[5] = { 1, 2, 3, 4, 5 };
int *ptr = (int *)(&a + 1);
printf("%d,%d", *(a + 1), *(ptr - 1));
system("pause");
return 0;
}
//笔试2
//由于还没学习结构体,这里告知结构体的大小是20个字节
struct Test
{
int Num;
char *pcName;
shortsDate;
char cha[2];
shortsBa[4];
}*p;
假设p 的值为0x100000。 如下表表达式的值分别为多少?
p + 0x1 = 0x___ ? 0x100014 [实际是加了整个结构体大小]【十进制20 = 十六进制14】
(unsigned long)p + 0x1 = 0x___ ? 0x100001 [整形加1就是直接加1]
(unsigned int*)p + 0x1 = 0x___ ? 0x100004 [指针类型是4个字节]
//笔试3
int main()
{
int a[4] = { 1, 2, 3, 4 };
int *pstr1 = (int *)(&a + 1);
int *pstr2 = (int *)((int)a + 1);
printf("%x, %x\n", pstr1[-1], *pstr2);
system("pause");
return 0;
}
//笔试4
int main(int argc, char * argv[])
{
int a[3][2] = { (0, 1), (2, 3), (4, 5) };
int *p;
p = a[0];
printf("%d\n", p[0]);
system("pause");
return 0;
}
//笔试5
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]);
system("pause");
return 0;
}
//笔试6
int main()
{
int aa[2][5] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int *ptr1 = (int *)(&aa + 1);
int *ptr2 = (int *)(*(aa + 1));
printf("%d,%d", *(ptr1 - 1), *(ptr2 - 1));
system("pause");
return 0;
}