当前位置:网站首页>C语言的指针符号到底靠近变量类型还是变量名?
C语言的指针符号到底靠近变量类型还是变量名?
2022-04-23 06:20:00 【猿知】
今天在复习数据结构时,C语言实现线性表用到了指针,对指针符号的位置存疑,遂查询了一下:
在C语言中只要使用指针,必然用到* 运算符。然后经常会看到不同的书中*有靠近变量类型的,有靠近变量名称的,很迷惑这两者有什么区别。后来上网查证了一下,总结如下:
总体来说,*靠近哪一个都可以,编译器都会认为是指针变量,所以本质是一样的。但是两个形式有不同的优点。
int* p;
这个可以理解为p是int类型的指针。而下面这个
int *p;
可以理解为有一个指针p是int类型,实际上也就是int类型的指针而已。
但是int* p这种类型当定义较多变量名称时,容易产生误解。例如:
int* p,q;
这句话的意思是p是int型指针变量,而q只是int类型变量。这种形式等价于
int *p,q; //即int *p,int q
因此,在这种情况下,可以将*靠近变量名称,而不是变量类型。如下:
int *p,q;
这样不会产生歧义。当然,多分几行写就不存在这个问题了,当然可以。
版权声明
本文为[猿知]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Magic_Zsir/article/details/123598427
边栏推荐
猜你喜欢

可视化常见绘图(四)柱状图

可视化之路(十二)Collection类详解

DMR system solution of Kaiyuan MINGTING hotel of Fengqiao University

Meishe technology launches professional video editing solution for desktop -- Meiying PC version

Source Insight 4.0常见问题

使用compressorjs压缩图片,优化功能,压缩所有格式的图片

可视化常见问题解决方案(九)背景颜色问题

How does the public and Private Integrated walkie talkie realize cooperative work under multi-mode communication?

Int8 quantification and inference of onnx model using TRT

el-table 横向滚动条固定在可视窗口底部
随机推荐
电力行业巡检对讲通信系统
Emergency communication system for flood control and disaster relief
javscript获取文件真实后缀名
HuggingFace
el-table的数据更新后,页面中数据未更新this.$forceUpdate()无效果
Typora操作技巧说明(一)
PyTorch 22. Pytorch common code snippet collection
SDC intelligent communication patrol management system of Nanfang investment building
golang实现MD5,SHA256,bcrypt加密
null和undefined的区别
北峰通信助力湛江市消防支队构建PDT无线通信系统
使用compressorjs压缩图片,优化功能,压缩所有格式的图片
数据分析学习(一)数据分析和Numpy基础
应急医疗通讯解决方案|MESH无线自组网系统
PyTorch 11. Regularization
PyTorch 14. Module class
Pep517 error during pycuda installation
vim+ctags+cscpope开发环境搭建指南
Emergency air space integrated communication system scheme of Guangxi Power Grid
Gather, unsqueeze and other operators when PTH is converted to onnx