指针笔试题(C语言)

#define _CRT_SECURE_NO_WARNINGS 1
#include
//指针笔试题
#if 0
//笔试题1:
int main()
{
int a[5] = { 1, 2, 3, 4, 5 };
//&a取地址数组名–>数组指针->数组指针+1->跳过整个数组
int *ptr = (int *)(&a + 1);
printf("%d,%d\n", *(a + 1), (ptr - 1)); //结果为:2 , 5 //(a + 1)==a[1]
return 0;
}

//笔试题2
//结构体的大小为20字节
struct Test
{
int Num;
char *pcName;
short sDate;
char cha[2];
short sBa[4];
}p;
//假设p的值为0x100000.如下表达式的值为多少?
int main()
{
printf("%p\n", p + 0x1);
printf("%p\n", (unsigned long)p + 0x1);
printf("%p\n", (unsigned int
)p + 0x1);
return 0;
}

//笔试题3
int main()
{
int a[4] = { 1, 2, 3, 4 }; //a指向数组首元素的地址
int *ptr1 = (int *)(&a + 1); //去地址数组名–数组指针–数组指针+1–跳过整个元素
int *ptr2 = (int *)((int)a + 1);
printf("%x,%x \n", ptr1[-1], *ptr2);//结果为:4,2000000
return 0;
}

//笔试题4
int main(int argc, char * argv[])
{
int a[3][2] = { (0, 1), (2, 3), (4, 5) };//注意区分()和{}的区别,它所代表的二维数组为:1 3, 5 0,0 0.
int *p;
p = a[0];
printf("%d\n", p[0]);//结果为1
}

//笔试题5
int main()
{
int a[5][5];//a转成指针:int(*)[5]
int(*p)[4];
p = a;
printf("%p,%d\n", &p[4][2] - &a[4][2], &p[4][2] - &a[4][2]);//[4][2]第四个元素当中的下标为2的数
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\n",
(ptr1-1),*(ptr2-1));//结果为:10 , 5
return 0;
}

//笔试题7
int main()
{
char *a[] = { “work”, “at”, “alibaba” };//数组指针:char *a[],指向数组首元素地址
char**pa = a;
pa++;
printf("%s\n", *pa);//—>at
return 0;
}
#endif

//笔试题8
int main()
{
char c[] = { “ENTER”, “NEW”, “POINT”, “FIRST” };
charcp[] = { 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;
}

你可能感兴趣的:(指针笔试题(C语言))