当前位置:网站首页>Analysis of problems related to C language pointer
Analysis of problems related to C language pointer
2022-07-18 01:44:00 【Lulu ovo】
1. Determine the output of the following three expressions ?
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;
}a. First analyze the concept defined according to the structure to know this p Pointer to this structure ,p+0x1(16 Base number ), That is to say p+1,p For a pointer +1 That is to skip one p Related types . So for p The address of + The bytes it occupies 20 by :0x100014.
b. The second is the same as the first , But it needs to be added because its type is forcibly converted to (unsigned long) Is an unsigned long shape , So direct integer plus one , by :0x100001
c. The third is the same as above , Because it is transformed into ( Pointer types ) So the pointer is four bytes, so add four directly , by :0x100004
2. Judge the following output value
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);//4
return 0;
}
a.&a because a For array name , Address it directly into an array pointer int (*)[4], When it is added by one, because it is a pointer type , So skip the length of a pointer type directly , The array pointer type length is 4*4 Bytes , Jump to the array element 4 The last one of them , Translates into int* Pointer variables exist for type ptr1 in , When it is printed at the bottom , the ptr1[-1] operation , This operation is equivalent to *(ptr1-1), namely ptr1 This pointer moves forward one bit and dereferences , Finally, I will use %x Print 16 Base number , by :4.
b. Drawing solution :
3. Judge the following output value
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;
}a. The illustration

4. Judge the following output value .
int main()
{
char* c[] = { "ENTER","NEW","POINT","FIRST" };
char** cp[] = { c + 3,c + 2,c + 1,c };
char*** cpp = cp;
printf("%s\n", **++cpp);//point
printf("%s\n", *-- * ++cpp + 3);//er
printf("%s\n", *cpp[-2] + 3);//rt
printf("%s\n", cpp[-1][-1] + 1);//ew
return 0;
}
The illustration :

边栏推荐
- [exercise C] number of varieties of daffodils
- C语言实现三子棋
- Idea setting / modifying shortcut keys
- C. K-beautiful Strings
- Today's sleep quality record is 80 points
- How much do you know about programming paradigms -- clarify the mainstream programming paradigms
- 【C】 Address of array
- C语言实现手机通讯录
- Solution of in multi column special query type in laravel
- 【HCIA】OSI 模型
猜你喜欢
![[C exercise] print 'x' graphics](/img/4a/d9b69b787bf585b4786b2074063370.png)
[C exercise] print 'x' graphics

Realizing Halcon scale with MATLAB low-level source code_ image_ Range (can be used for background segmentation)

Introduction to redis

解析协同办公“协同”为何意,数字化办公又如何轻松“破题”?

【C】指针进阶

IDEA 设置 / 修改快捷键

数据湖(十九):SQL API 读取Kafka数据实时写入Iceberg表

Matlab low-level source code realizes Prewitt edge detection and Sobel, Laplace edge detection (the implementation effect is consistent with Halcon)

在线综艺冷场:“爱优腾芒”放不开,“抖快B”拿不下

Realizing Halcon scale with MATLAB low-level source code_ image_ Max operator effect
随机推荐
What designs are needed in the architecture to build a general monitoring and alarm platform
Mysql事务
Realizing Halcon scale with MATLAB low-level source code_ image_ Max operator effect
机器学习预备知识:分类与回归
解析协同办公“协同”为何意,数字化办公又如何轻松“破题”?
HashSet和TreeSet
【C 练习】打印0~100000所有「水仙花数」
STM32 application development practice tutorial: application development of environmental light intensity monitoring
针对采集丢权益,企业站,还值得深耕内容吗?
善良的人都晚熟
Some notes on kubelet in kubernetes
Network security (1)
树莓派串口通信
STM32 application development practice tutorial: application development of persistent storage of environmental parameters
Thinking of reading
Data Lake (19): SQL API reads Kafka data and writes it to iceberg table in real time
What is CDN acceleration
[C exercise] inverted string
Vulnerability scanning tools Nessus, rapid7 insightvm, OpenVAS installation & simple use
企业站,有排名,没有流量,怎么办?