当前位置:网站首页>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;
}

边栏推荐
- v-for遍历元素样式失效
- 动态库基本原理和使用方法,-fPIC 选项的来龙去脉
- [C language] objective questions - knowledge points
- 语义分割模型库segmentation_models_pytorch的详细使用介绍
- 22年秋招心得
- What if the testing process is not perfect and the development is not active?
- fabulous! How does idea open multiple projects in a single window?
- Smart regulation enters the market, where will meituan and other Internet service platforms go
- 5g NR system messages
- Kubernetes Static Pod (静态Pod)
猜你喜欢

Smart regulation enters the market, where will meituan and other Internet service platforms go

My best game based on wechat applet development

深潜Kotlin协程(二十二):Flow的处理

《因果性Causality》教程,哥本哈根大学Jonas Peters讲授
![[Yugong series] go teaching course 006 in July 2022 - automatic derivation of types and input and output](/img/79/f5cffe62d5d1e4a69b6143aef561d9.png)
[Yugong series] go teaching course 006 in July 2022 - automatic derivation of types and input and output

RPA cloud computer, let RPA out of the box with unlimited computing power?

基于卷积神经网络的恶意软件检测方法

快速上手使用本地测试工具postman

搭建ADG过程中复制报错 RMAN-03009 ORA-03113

RPA云电脑,让RPA开箱即用算力无限?
随机推荐
SDNU_ ACM_ ICPC_ 2022_ Summer_ Practice(1~2)
Leetcode brush questions
5G NR 系统消息
Jouer sonar
Course of causality, taught by Jonas Peters, University of Copenhagen
DNS series (I): why does the updated DNS record not take effect?
1293_ Implementation analysis of xtask resumeall() interface in FreeRTOS
DNS 系列(一):为什么更新了 DNS 记录不生效?
Smart regulation enters the market, where will meituan and other Internet service platforms go
服务器防御DDOS的方法,杭州高防IP段103.219.39.x
They gathered at the 2022 ecug con just for "China's technological power"
Flask learning record 000: error summary
Solution to the problem of unserialize3 in the advanced web area of the attack and defense world
Single machine high concurrency model design
基于人脸识别实现课堂抬头率检测
第一讲:链表中环的入口结点
詹姆斯·格雷克《信息简史》读后感记录
Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?
【obs】Impossible to find entrance point CreateDirect3D11DeviceFromDXGIDevice
韦东山第三期课程内容概要