指针声明之间的区别 [英] Differences between pointer declaration
本文介绍了指针声明之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这两个声明之间有区别吗?
Is there any differences between these two declarations?
int* a;
int *a;
或者这两个声明是相同的(指向整数的指针)?
Or these two declarations are the same (pointer to an integer)?
推荐答案
它们是完全一样的,但这是我几年前第一次学习C时遇到的一个小难题.*绑定到变量,而不是类型.这意味着
They're exactly the same, but here's a small gotcha I came across when first learning C years ago. The * binds to the variable, not the type. This means that
int* a, b;
将 a
声明为int的指针,将 b
声明为 int 的指针.要将两者都声明为指针,应该这样做.
Declares a
as a pointer to int, and b
as an int. To declare both as pointers, one should do.
int *a, *b;
这就是为什么我更喜欢在名称旁边放置 *
.
This is why I prefer to place the *
next to the name.
这篇关于指针声明之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文