当前位置:网站首页>常量指针、指针常量
常量指针、指针常量
2022-07-24 10:18:00 【乘风破浪的阿呆】
C语言中的常量指针、指针常量在lua中的应用
常量指针是指针指向的内容是常量,可以有一下两种定义方式。
const int* n;
int const* n;
需要注意的是一下两点:
1、常量指针说的是不能通过这个指针改变变量的值,但是还是可以通过其他的引用来改变变量的值的。
int a=5;
const int* n=&a;
a=6;
2、常量指针指向的值不能改变,但是这并不是意味着指针本身不能改变,常量指针可以指向其他的地址。
int a=5;
int b=6;
const int* n=&a;
n=&b;
指针常量是指指针本身是个常量,不能在指向其他的地址,写法如下:
int*const n;
需要注意的是,指针常量指向的地址不能改变,但是地址中保存的数值是可以改变的,可以通过其他指向改地址的指针来修改。
int a=5;
int*p=&a;
int* const n=&a;
*p=8;
区分常量指针和指针常量的关键就在于星号的位置,我们以星号为分界线,如果const在星号的左边,则为常量指针,如果const在星号的右边则为指针常量。如果我们将星号读作‘指针’,将const读作‘常量’的话,内容正好符合。int const * n;是常量指针,int *const n;是指针常量。
指向常量的常指针
const int* const a;
是以上两种的结合,指针指向的位置不能改变并且也不能通过这个指针改变变量的值,但是依然可以通过其他的普通指针改变变量的值。
const int* const luaX_tokens [];
在lua源码中就是通过这种方式实现了一个常量数组,定义了一个常量指针指向这个常量数组。
边栏推荐
- [STM32 learning] (4) press the key to control the flow light
- Mysql InnoDB下联合索引的索引数量?
- Build a live broadcast platform based on webrtc
- Websocket 协议解读-RFC6455
- In the envy of LETV, there is a "meaning crisis" of contemporary workers
- Redis configuration serialization
- Query about operating system security patch information
- Yarn: unable to load file
- Will not be rejected! Learn the distributed architecture notes sorted out by Alibaba Daniel in 35 days, with a salary increase of 20K
- [STM32 learning] (16) STM32 realizes LCD1602 display (74HC595 drive) - 4-bit bus
猜你喜欢

757. Set the intersection size to at least 2: greedy application question

Dynamic programming -- a collection of stock problems

NiO knowledge points

Home raiding III (leetcode-337)
![[robot learning] mechanism kinematics analysis and MATLAB simulation (3D model +word report +matlab program)](/img/dd/d29a5be7306580ad388ba6487d230f.png)
[robot learning] mechanism kinematics analysis and MATLAB simulation (3D model +word report +matlab program)

Record AP and map calculation examples

Ask you to build a small program server
![[correcting Hongming] what? I forgot to take the](/img/41/c8fa6380ab63949ae6d904fdbb005c.png)
[correcting Hongming] what? I forgot to take the "math required course"!
![[STM32 learning] (11) STM32 Mifare_ Use of one (S50) m1s50 (read, write, key modification, control bit interpretation)](/img/fd/4290525914b5146fe0eb653517fef9.png)
[STM32 learning] (11) STM32 Mifare_ Use of one (S50) m1s50 (read, write, key modification, control bit interpretation)

CMS vulnerability recurrence - foreground arbitrary user password modification vulnerability
随机推荐
PostgreSQL rounding
Raspberry Pie: [failed] failed to start /etc/rc local Compatibility.
[STM32 learning] (18) STM32 realizes LCD12864 display - parallel implementation of 8-bit bus
脚手架文件目录说明、文件暴露
Interpretation of websocket protocol -rfc6455
How to solve command 'xxx GCC' not found, but can be installed with:??
Kotlin domain specific language (DSL)
Zoj1137+ operation 1 -- May 28, 2022
Mysql database JDBC programming
Tag the specified commit and submit the tag
System a uses window.open to call system B, and system B carries data back to system a after processing the business
[STM32 learning] (6) use of serial port 1 (usart1)
Activity exception lifecycle
Raspberry Pie:: no space left on device
Trie tree template 2
图模型2--2022-5-13
JS 84*148=b6a8 how many decimal places can you make both sides equal
Set scrolling for the box
Sub query of multi table query_ Single row and single column
When the hot tea is out of stock, what does the new tea drink rely on to continue its life?