当前位置:网站首页>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;
}
边栏推荐
- Solution to prompt configure: error: curses library not found when configuring and installing crosstool ng tool
- SDNU_ ACM_ ICPC_ 2022_ Summer_ Practice(1~2)
- 攻防演练中沙盘推演的4个阶段
- Reentrantlock fair lock source code Chapter 0
- ABAP ALV LVC模板
- Application practice | the efficiency of the data warehouse system has been comprehensively improved! Data warehouse construction based on Apache Doris in Tongcheng digital Department
- C# 泛型及性能比较
- Su embedded training - Day3
- 韦东山第二期课程内容概要
- ReentrantLock 公平锁源码 第0篇
猜你喜欢
【笔记】常见组合滤波电路
CVE-2022-28346:Django SQL注入漏洞
Huawei switch s5735s-l24t4s-qa2 cannot be remotely accessed by telnet
搭建ADG过程中复制报错 RMAN-03009 ORA-03113
5G NR 系统消息
第一讲:链表中环的入口结点
备库一直有延迟,查看mrp为wait_for_log,重启mrp后为apply_log但过一会又wait_for_log
How to insert highlighted code blocks in WPS and word
ReentrantLock 公平锁源码 第0篇
Play sonar
随机推荐
搭建ADG过程中复制报错 RMAN-03009 ORA-03113
Leetcode brush questions
《因果性Causality》教程,哥本哈根大学Jonas Peters讲授
【转载】解决conda安装pytorch过慢的问题
Huawei switch s5735s-l24t4s-qa2 cannot be remotely accessed by telnet
Binder核心API
SDNU_ ACM_ ICPC_ 2022_ Summer_ Practice(1~2)
8道经典C语言指针笔试题解析
22年秋招心得
Operating system principle --- summary of interview knowledge points
QT establish signal slots between different classes and transfer parameters
DNS series (I): why does the updated DNS record not take effect?
[研发人员必备]paddle 如何制作自己的数据集,并显示。
3年经验,面试测试岗20K都拿不到了吗?这么坑?
Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?
tourist的NTT模板
商品的设计等整个生命周期,都可以将其纳入到产业互联网的范畴内
应用实践 | 数仓体系效率全面提升!同程数科基于 Apache Doris 的数据仓库建设
CVE-2022-28346:Django SQL注入漏洞
Zhou Hongqi, 52 ans, est - il encore jeune?