当前位置:网站首页>【校招面经】8道指针面试真题,快来检测自己掌握了几道。
【校招面经】8道指针面试真题,快来检测自己掌握了几道。
2022-07-24 19:17:00 【月亮嚼成星~】


作者简介:一名大一在校生
个人主页:月亮嚼成星~
个人WeChat:yx1552029968
系列专栏:校招面经
每日一句:努力和收获,都是自己的,与他人无关。最大的成就感,就是一直在朝着自己想要的方向前进。
目录
指针面试真题一
给你一段代码,问程序的结果是什么?
#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;
}这道题比较简单,大家稍微思考一下应该就知道了,不理解的看下面哦!
知识点补充:
指针类型决定了指针向前或向后走一步的步长(±整数),单位是字节。详情请看我这一篇文章:
解题思路:

指针面试真题二
已知结构体大小是20字节,问下列表达式的值分别是多少?
#include<stdio.h>
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;
}解题思路:

指针面试真题三
在小端存储模式下,给出下面一段程序,问输出什么?(vs2019采用的小端存储)
#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;
}
知识点补充
这里要补充大小端的概念:
大端字节序存储:当一个数据的低位放到高地址处,数据的高位放到低地址处;
小端字节序存储:当一个数据的低位放到低地址处,数据的高位放到高地址处.
(不了解大小端存储的博主后续会出相应的内容)
解题思路

指针面试真题四
这题不难,不过有小坑哦
#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;
}
知识点补充
逗号表达式,从左向右依次执行,整个表达式的结果是最后一个表达式的结果,这里需要注意哦,每个表达式都会执行计算,只不过选用最后一个表达式的结果作为整个表达式的结果。了解更多,点击博主的这篇文章:对C语言操作符的再认识
解题思路

指针面试真题五
给出如下程序,问输出什么值?
#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;
}
知识点补充
指针-指针:
注意哦,使用指针-指针运算的时候,前提是两个指针指向的是同一块内存空间,那何为指向同一块内存空间呢?最典型的例子就是数组。
指针-指针其实表示的是两个指针中间的元素个数,注意哦,不是中间有几个字节。


指针面试真题六
很简单的一道题:
#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;
}解题思路

指针面试真题七
这道题实际上是为下一题过度准备的。
#include <stdio.h>
int main()
{
char* a[] = { "work","at","alibaba" };
char** pa = a;
pa++;
printf("%s\n", *pa);
return 0;
}
解题思路

指针面试真题八
注意哦,这道题算是这几道中难度最大的一道,但是有了前一题的思路,这道题也就不再那么难以理解。
#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;
}
解题思路
一开始,在内存中是这么存储的:





多谢兄弟们
码字不易,求个三连。

边栏推荐
- Mysql数据库,子查询,union,limit篇
- PWN learning
- Web
- Clion configuring WSL tool chain
- DDR SDRAM board design guide
- How to convert the world coordinates of unity's camera into view matrix
- Hidden Markov model HMM
- What are the benefits of knowledge management in enterprises?
- MySQL final chapter
- Unity框架之ConfigManager【Json配置文件读写】
猜你喜欢
![[JVM learning 03] class loading and bytecode Technology](/img/b4/9482b02b58580171235fd4c36129e9.png)
[JVM learning 03] class loading and bytecode Technology
![[JVM learning 04] JMM memory model](/img/8c/0f76be122556301a5af140e34b55f4.png)
[JVM learning 04] JMM memory model

Clion configuring WSL tool chain

Tencent Browser service TBS usage

Summary of articles in 2020

Literature reading: gopose 3D human pose estimation using WiFi

Nacos introduction and console service installation

Why are there loopholes in the website to be repaired

暑期牛客多校1: I Chiitoitsu(期望dp,求逆元)

Techempower web framework performance test 21st round results release --asp Net core continue to move forward
随机推荐
Hangdian multi School Game 1 question 3 backpack (XOR dp+bitset)
2020-2021 new technology lecture course
Colon sorting code implementation
2022暑期杭电多校第一场1012Alice and Bob(博弈论)
Leetcode402 remove K digits
Pay close attention! List of the latest agenda of 2022 open atom open source Summit
JVM method call
2022 Hangdian multi school second session 1009 shuangq (Mathematics)
Integer
Zooinspector Download
Data model subclassing reference
Chapter 4 compound type
On July 31, 2022, the dama-cdga/cdgp data governance certification class was opened!
Meshlab & PCL ISS key points
The difference between static method and instance method
Taokeeper environment setup
Why is gradient the fastest changing direction of function
文献阅读:GoPose 3D Human Pose Estimation Using WiFi
[laser principle and application -6]:q switching element and Q drive circuit board
Profile environment switching
作者简介:一名大一在校生
个人主页:
个人WeChat:yx1552029968
系列专栏:
每日一句: