当前位置:网站首页>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;
}
边栏推荐
- 【测试面试题】页面很卡的原因分析及解决方案
- [C language] objective questions - knowledge points
- Summary of the third course of weidongshan
- Jouer sonar
- 从Starfish OS持续对SFO的通缩消耗,长远看SFO的价值
- Tapdata 的 2.0 版 ,开源的 Live Data Platform 现已发布
- 玩转Sonar
- [OBS] the official configuration is use_ GPU_ Priority effect is true
- 1293_ Implementation analysis of xtask resumeall() interface in FreeRTOS
- They gathered at the 2022 ecug con just for "China's technological power"
猜你喜欢
搭建ADG过程中复制报错 RMAN-03009 ORA-03113
1293_FreeRTOS中xTaskResumeAll()接口的实现分析
SDNU_ACM_ICPC_2022_Summer_Practice(1~2)
玩轉Sonar
Codeforces Round #804 (Div. 2)(A~D)
51 communicates with the Bluetooth module, and 51 drives the Bluetooth app to light up
测试流程不完善,又遇到不积极的开发怎么办?
【测试面试题】页面很卡的原因分析及解决方案
[programming problem] [scratch Level 2] 2019.09 make bat Challenge Game
Tencent security released the white paper on BOT Management | interpreting BOT attacks and exploring ways to protect
随机推荐
They gathered at the 2022 ecug con just for "China's technological power"
他们齐聚 2022 ECUG Con,只为「中国技术力量」
Su embedded training - day4
攻防演练中沙盘推演的4个阶段
玩转Sonar
[C language] objective questions - knowledge points
ReentrantLock 公平锁源码 第0篇
Lecture 1: the entry node of the link in the linked list
Four stages of sand table deduction in attack and defense drill
赞!idea 如何单窗口打开多个项目?
【obs】Impossible to find entrance point CreateDirect3D11DeviceFromDXGIDevice
【转载】解决conda安装pytorch过慢的问题
Emotional post station 010: things that contemporary college students should understand
【愚公系列】2022年7月 Go教学课程 006-自动推导类型和输入输出
取消select的默认样式的向下箭头和设置select默认字样
How does the markdown editor of CSDN input mathematical formulas--- Latex syntax summary
How is it most convenient to open an account for stock speculation? Is it safe to open an account on your mobile phone
"An excellent programmer is worth five ordinary programmers", and the gap lies in these seven key points
RPA云电脑,让RPA开箱即用算力无限?
Codeforces Round #804 (Div. 2)(A~D)