当前位置:网站首页>8道经典C语言指针笔试题解析
8道经典C语言指针笔试题解析
2022-07-07 22:51:00 【real Wangyanbin】
笔试题1:
#include<stdio.h>
int main()
{
int a[5] = {
1, 2, 3, 4, 5 };
int *ptr = (int *)(&a + 1);
printf( "%d,%d", *(a + 1), *(ptr - 1));
return 0;
}
//程序的结果是什么?

笔试题2:
#include<stdio.h>
//由于还没学习结构体,这里告知结构体的大小是20个字节
struct Test
{
int Num;
char *pcName;
short sDate;
char cha[2];
short sBa[4];
}*p;
//假设p 的值为0x100000。 如下表表达式的值分别为多少?
//已知,结构体Test类型的变量大小是20个字节
int main()
{
printf("%p\n", p + 0x1);
printf("%p\n", (unsigned long)p + 0x1);
printf("%p\n", (unsigned int*)p + 0x1);
return 0;
}

笔试题3
#include<stdio.h>
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;
}
//输出结果是多少

笔试题4
#include <stdio.h>
int main()
{
int a[3][2] = {
(0, 1), (2, 3), (4, 5) };
int *p;
p = a[0];
printf( "%d", p[0]);
return 0;
}

笔试题5
#include<stdio.h>
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;
}

笔试题6
#include<stdio.h>
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));
return 0;
}

笔试题7
#include <stdio.h>
int main()
{
char* a[] = {
"work","at","alibaba" };
char** pa = a;
pa++;
printf("%s\n", *pa);
return 0;
}

笔试题8:
#include<stdio.h>
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;
}

边栏推荐
- [programming problem] [scratch Level 2] draw ten squares in December 2019
- Basic principle and usage of dynamic library, -fpic option context
- Is 35 really a career crisis? No, my skills are accumulating, and the more I eat, the better
- Kubernetes Static Pod (静态Pod)
- 3 years of experience, can't you get 20K for the interview and test post? Such a hole?
- Reentrantlock fair lock source code Chapter 0
- v-for遍历元素样式失效
- 80% of the people answered incorrectly. Does the leaf on the apple logo face left or right?
- 什么是负载均衡?DNS如何实现负载均衡?
- Sqlite数据库存储目录结构邻接表的实现2-目录树的构建
猜你喜欢

Lecture 1: the entry node of the link in the linked list

After going to ByteDance, I learned that there are so many test engineers with an annual salary of 40W?

5g NR system messages
![[question de programmation] [scratch niveau 2] oiseaux volants en décembre 2019](/img/5e/a105f8615f3991635c9ffd3a8e5836.png)
[question de programmation] [scratch niveau 2] oiseaux volants en décembre 2019

fabulous! How does idea open multiple projects in a single window?

Huawei switch s5735s-l24t4s-qa2 cannot be remotely accessed by telnet

“一个优秀程序员可抵五个普通程序员”,差距就在这7个关键点

When creating body middleware, express Is there any difference between setting extended to true and false in urlencoded?

The underlying principles and templates of new and delete
![[OBS] the official configuration is use_ GPU_ Priority effect is true](/img/df/772028e44776bd667e814989e8b09c.png)
[OBS] the official configuration is use_ GPU_ Priority effect is true
随机推荐
The difference between get and post
Notice on organizing the second round of the Southwest Division (Sichuan) of the 2021-2022 National Youth electronic information intelligent innovation competition
Summary of weidongshan phase II course content
攻防演练中沙盘推演的4个阶段
redis你到底懂不懂之list
【obs】官方是配置USE_GPU_PRIORITY 效果为TRUE的
接口测试进阶接口脚本使用—apipost(预/后执行脚本)
Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?
ReentrantLock 公平锁源码 第0篇
Deep dive kotlin collaboration (the end of 23): sharedflow and stateflow
备库一直有延迟,查看mrp为wait_for_log,重启mrp后为apply_log但过一会又wait_for_log
ABAP ALV LVC模板
Deep dive kotlin synergy (XXII): flow treatment
51 communicates with the Bluetooth module, and 51 drives the Bluetooth app to light up
服务器防御DDOS的方法,杭州高防IP段103.219.39.x
Langchao Yunxi distributed database tracing (II) -- source code analysis
Basic principle and usage of dynamic library, -fpic option context
QT adds resource files, adds icons for qaction, establishes signal slot functions, and implements
腾讯安全发布《BOT管理白皮书》|解读BOT攻击,探索防护之道
“一个优秀程序员可抵五个普通程序员”,差距就在这7个关键点