当前位置:网站首页>Pointer - character pointer
Pointer - character pointer
2022-07-06 00:18:00 【It's Yi'an】
Part1:
Array function parameter Character pointer Basic usage Constant string
When we pass an array into a function , In fact, what is passed in is an address , Modify the content in the address , On the sizeof What you get is not the space occupied by the array , It's the space occupied by the pointer .
#include<stdio.h>
void mylen(int arr[]) {
int sz = sizeof(arr) / sizeof(arr[0]);
printf("%d", sz);
}
int main(void) {
int arr[10] = { 0 };
mylen(arr);
return 0;
}
// The result is 1/2Character pointer : We usually define a character first a, Define a character pointer variable to point to a.
char test='a';
char* p=&test;Or define a character array , Define a pointer variable to point to it .
char arr[]="abcdef";
char* p=arr;If we define a pointer variable directly , Then assign a character or string to the pointer variable , In fact, it is the address of the first character . Such a string is called a constant string .
char* p="abcdef";Why is it called a constant string ? According to our previous understanding , We have a pointer to the first character. Can we modify it ?
#include<stdio.h>
int main(void) {
char* p = "abcdef";
*p = 'W';
printf("%s", p);
}The program running here will crash . But the compiler does not report an error , To solve this problem , We can add const
const char* p="abcdef";Part2:
Common mistakes Compare character arrays Constant space
We often encounter the judgment condition of comparing two arrays when we are doing problems , At this time, if you directly compare array names , That's actually comparing addresses .
char arr[] = "abcdef";
char arr1[] = "abcdef";
if(arr==arr1)// The address is different Constant string , If two constant strings are the same , Then the system will not open up two spaces for storage , At this time, if you point to it with two pointers , Its storage address is the same .
char* p = "abcdef";
char* q = "abcdef";
if(p==q)// Because constants are the same ,p And q The value of is the same 边栏推荐
- [Luogu cf487e] tours (square tree) (tree chain dissection) (line segment tree)
- Mathematical model Lotka Volterra
- 云呐|公司固定资产管理系统有哪些?
- Yunna | what are the main operating processes of the fixed assets management system
- 时区的区别及go语言的time库
- 传输层协议------UDP协议
- Shardingsphere source code analysis
- Detailed explanation of APP functions of door-to-door appointment service
- Problems encountered in the database
- 亲测可用fiddler手机抓包配置代理后没有网络
猜你喜欢

Key structure of ffmpeg - avformatcontext
![[binary search tree] add, delete, modify and query function code implementation](/img/38/810a83575c56f17a7a0ed428a2e02e.png)
[binary search tree] add, delete, modify and query function code implementation

MySQL functions

Configuring OSPF load sharing for Huawei devices

Gavin teacher's perception of transformer live class - rasa project actual combat e-commerce retail customer service intelligent business dialogue robot system behavior analysis and project summary (4

Effet Doppler (déplacement de fréquence Doppler)

关于slmgr命令的那些事

如何解决ecology9.0执行导入流程流程产生的问题

There is no network after configuring the agent by capturing packets with Fiddler mobile phones

Teach you to run uni app with simulator on hbuilderx, conscience teaching!!!
随机推荐
Search (DFS and BFS)
Configuring OSPF load sharing for Huawei devices
[designmode] Decorator Pattern
[Luogu cf487e] tours (square tree) (tree chain dissection) (line segment tree)
FFMPEG关键结构体——AVFormatContext
提升工作效率工具:SQL批量生成工具思想
【DesignMode】组合模式(composite mode)
Recognize the small experiment of extracting and displaying Mel spectrum (observe the difference between different y_axis and x_axis)
MySQL存储引擎
Gavin teacher's perception of transformer live class - rasa project actual combat e-commerce retail customer service intelligent business dialogue robot system behavior analysis and project summary (4
LeetCode 6004. Get operands of 0
[Luogu p3295] mengmengda (parallel search) (double)
Single merchant v4.4 has the same original intention and strength!
Huawei equipment configuration ospf-bgp linkage
PV static creation and dynamic creation
Global and Chinese market of valve institutions 2022-2028: Research Report on technology, participants, trends, market size and share
Miaochai Weekly - 8
[gym 102832h] [template] combination lock (bipartite game)
AtCoder Beginner Contest 254【VP记录】
MySql——CRUD