当前位置:网站首页>Programmers can make mistakes. Basic pointers and arrays of C language
Programmers can make mistakes. Basic pointers and arrays of C language
2022-07-06 12:02:00 【csdndulala】
// a.c
char name[] = "tom";
// b.c
extern char *name;
void main()
{
printf("%s", name);
}
Execution will fail , Why? ?
Background knowledge 0
The executable contains 4 Class segment content :
.text Store code snippets
.data Store data segments . Initialized global or static variables
.rodata Store read-only data segments . Like string constants
.bss Store uninitialized global or static variables .Background knowledge 1
char a[] = “abc”;
char *b = “def”;
a and b What's the difference? ? In which paragraph ?
difference 1:b It's a variable , Have your own address and stored data ;a It's just a name ,a Namely “abc” The address of .( You can print a and &a, It's the same )
difference 2:“abc” Stored in data paragraph ,“def” Stored in rodata paragraph
difference 3:“abc” The content can be modified ,“def” The content cannot be modifiedBackground knowledge 2
char a[] = “abc”;
char *b = a;
ask :a[0] and b[0] What's the difference? ?
a[0] Direct value ;b[0] First find b Stored values (a Address ), And then according to a Address value
Take the address casually a The value of is 0x3315,a[0] The address is also 0x3315
// a.c
char name[] = "tom";
// b.c
extern char *name;
void main()
{
printf("%s", name);
}
So in b.c in :extern char *name; Statement name It's a pointer , So when printing name When , Will find name Stored content :“tom”, And then “tom” Take value as address .
resolvent 1:
// a.c
char name[] = "tom";
// b.c
extern char name[];
void main()
{
printf("%s", name);
}
resolvent 2:
// a.c
char *name = "tom";
// b.c
extern char *name;
void main()
{
printf("%s", name);
}
边栏推荐
- Togglebutton realizes the effect of switching lights
- A possible cause and solution of "stuck" main thread of RT thread
- Funny cartoon: Programmer's logic
- 2020 WANGDING cup_ Rosefinch formation_ Web_ nmap
- ARM PC=PC+8 最便于理解的阐述
- 程序员老鸟都会搞错的问题 C语言基础 指针和数组
- MATLAB学习和实战 随手记
- Fashion-Gen: The Generative Fashion Dataset and Challenge 论文解读&数据集介绍
- Distribute wxWidgets application
- Machine learning -- decision tree (sklearn)
猜你喜欢

B tree and b+ tree of MySQL index implementation

Comparaison des solutions pour la plate - forme mobile Qualcomm & MTK & Kirin USB 3.0
![[template] KMP string matching](/img/f9/cd8b6f8e2b0335c2ec0a76fc500c9b.jpg)
[template] KMP string matching
![[yarn] CDP cluster yarn configuration capacity scheduler batch allocation](/img/85/0121478f8fc427d1200c5f060d5255.png)
[yarn] CDP cluster yarn configuration capacity scheduler batch allocation

Analysis of charging architecture of glory magic 3pro

Unit test - unittest framework

Comparison of solutions of Qualcomm & MTK & Kirin mobile platform USB3.0

sklearn之feature_extraction.text.CountVectorizer / TfidVectorizer

Mall project -- day09 -- order module

機器學習--線性回歸(sklearn)
随机推荐
Wangeditor rich text reference and table usage
程序员老鸟都会搞错的问题 C语言基础 指针和数组
数据分析之缺失值填充(重点讲解多重插值法Miceforest)
Machine learning -- decision tree (sklearn)
Hutool中那些常用的工具类和方法
RuntimeError: cuDNN error: CUDNN_STATUS_NOT_INITIALIZED
树莓派 轻触开关 按键使用
Small L's test paper
Togglebutton realizes the effect of switching lights
Come and walk into the JVM
RT thread API reference manual
Time slice polling scheduling of RT thread threads
Funny cartoon: Programmer's logic
encoderMapReduce 随手记
Dead loop in FreeRTOS task function
ESP8266通过Arduino IDE连接Onenet云平台(MQTT)
Selective sorting and bubble sorting [C language]
vim命令行笔记
ESP8266使用arduino连接阿里云物联网
ARM PC=PC+8 最便于理解的阐述