当前位置:网站首页>Analysis of 8 classic C language pointer written test questions
Analysis of 8 classic C language pointer written test questions
2022-07-08 00:43:00 【real Wangyanbin】
Analysis of stylus test questions
Pen test 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;
}
// What is the result of the program ?
Pen test 2:
#include<stdio.h>
// Because I haven't learned the structure yet , The size of the structure is 20 Bytes
struct Test
{
int Num;
char *pcName;
short sDate;
char cha[2];
short sBa[4];
}*p;
// hypothesis p The value of is 0x100000. What are the values of the expressions in the following table ?
// It is known that , Structure Test The variable size of type is 20 Bytes
int main()
{
printf("%p\n", p + 0x1);
printf("%p\n", (unsigned long)p + 0x1);
printf("%p\n", (unsigned int*)p + 0x1);
return 0;
}
Pen test 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;
}
// What is the output
Pen test 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;
}
Pen test 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;
}
Pen test 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;
}
Pen test 7
#include <stdio.h>
int main()
{
char* a[] = {
"work","at","alibaba" };
char** pa = a;
pa++;
printf("%s\n", *pa);
return 0;
}
Pen test 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;
}
边栏推荐
- What if the testing process is not perfect and the development is not active?
- 应用实践 | 数仓体系效率全面提升!同程数科基于 Apache Doris 的数据仓库建设
- How can CSDN indent the first line of a paragraph by 2 characters?
- ThinkPHP kernel work order system source code commercial open source version multi user + multi customer service + SMS + email notification
- Cascade-LSTM: A Tree-Structured Neural Classifier for Detecting Misinformation Cascades(KDD20)
- Hotel
- Experience of autumn recruitment in 22 years
- Langchao Yunxi distributed database tracing (II) -- source code analysis
- Is it safe to open an account on the official website of Huatai Securities?
- 【愚公系列】2022年7月 Go教学课程 006-自动推导类型和输入输出
猜你喜欢
8道经典C语言指针笔试题解析
[programming problem] [scratch Level 2] 2019.09 make bat Challenge Game
他们齐聚 2022 ECUG Con,只为「中国技术力量」
Installation and configuration of sublime Text3
Reentrantlock fair lock source code Chapter 0
Interface test advanced interface script use - apipost (pre / post execution script)
备库一直有延迟,查看mrp为wait_for_log,重启mrp后为apply_log但过一会又wait_for_log
51与蓝牙模块通讯,51驱动蓝牙APP点灯
从Starfish OS持续对SFO的通缩消耗,长远看SFO的价值
从服务器到云托管,到底经历了什么?
随机推荐
爬虫实战(八):爬表情包
Langchao Yunxi distributed database tracing (II) -- source code analysis
Leetcode brush questions
去了字节跳动,才知道年薪 40w 的测试工程师有这么多?
[OBS] the official configuration is use_ GPU_ Priority effect is true
SDNU_ACM_ICPC_2022_Summer_Practice(1~2)
《因果性Causality》教程,哥本哈根大学Jonas Peters讲授
深潜Kotlin协程(二十二):Flow的处理
什么是负载均衡?DNS如何实现负载均衡?
【愚公系列】2022年7月 Go教学课程 006-自动推导类型和输入输出
Prompt configure: error: required tool not found: libtool solution when configuring and installing crosstool ng tool
Experience of autumn recruitment in 22 years
股票开户免费办理佣金最低的券商,手机上开户安全吗
5g NR system messages
Kubernetes static pod (static POD)
Password recovery vulnerability of foreign public testing
Development of a horse tourism website (optimization of servlet)
Tapdata 的 2.0 版 ,开源的 Live Data Platform 现已发布
Binder核心API
Service Mesh的基本模式