当前位置:网站首页>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 p3295] mengmengda (parallel search) (double)
- 权限问题:source .bash_profile permission denied
- Configuring OSPF GR features for Huawei devices
- 硬件及接口学习总结
- Key structure of ffmpeg - avframe
- [designmode] adapter pattern
- FFT learning notes (I think it is detailed)
- 18. (ArcGIS API for JS) ArcGIS API for JS point collection (sketchviewmodel)
- 时区的区别及go语言的time库
- The global and Chinese markets of dial indicator calipers 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢
随机推荐
软件测试工程师必会的银行存款业务,你了解多少?
Teach you to run uni app with simulator on hbuilderx, conscience teaching!!!
AtCoder Beginner Contest 254【VP记录】
wx.getLocation(Object object)申请方法,最新版
多线程与高并发(8)—— 从CountDownLatch总结AQS共享锁(三周年打卡)
[binary search tree] add, delete, modify and query function code implementation
JS can really prohibit constant modification this time!
QT a simple word document editor
Add noise randomly to open3d point cloud
Problem solving win10 quickly open ipynb file
MDK debug时设置数据实时更新
Wechat applet -- wxml template syntax (with notes)
【DesignMode】装饰者模式(Decorator pattern)
FFMPEG关键结构体——AVFrame
What is information security? What is included? What is the difference with network security?
[Chongqing Guangdong education] Chongqing Engineering Vocational and Technical College
多普勒效應(多普勒頻移)
Gd32f4xx UIP protocol stack migration record
LeetCode 6006. Take out the least number of magic beans
QT -- thread









![Atcoder beginer contest 254 [VP record]](/img/13/656468eb76bb8b6ea3b6465a56031d.png)