在C中,什么是声明指针的正确语法? [英] In C, what is the correct syntax for declaring pointers?

查看:93
本文介绍了在C中,什么是声明指针的正确语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我依稀记得在回答另一个问题之前看到这一点,但搜索未能得到答案。

I vaguely recall seeing this before in an answer to another question, but searching has failed to yield the answer.

我不记得是什么的正确的方式来声明是指针变量。它是:

I can't recall what is the proper way to declare variables that are pointers. Is it:

Type* instance;

或者

Type *instance;

虽然我知道双方会在大多数情况下编译,我相信有一些例子,这是显著,可能与在同一行声明相同类型的多个变量,所以谁能制造出比其他更有意义。

Although I know both will compile in most cases, I believe there are some examples where it is significant, possibly related to declaring multiple variables of the same type on the same line, and so one makes more sense than the other.

推荐答案

这是一个简单的,你怎么样的事情来阅读。

It is simply a matter of how you like to read it.

这是一些人把它像这样的原因:

The reason that some people put it like this:

Type *instance;

是因为它说,只有实例是一个指针。因为如果你有一个列表变量:

Is because it says that only instance is a pointer. Because if you have a list of variables:

int* a, b, c;

仅是一个指针,所以它是像这样

Only a is a pointer, so it's easier like so

int *a, b, c, *d;

如果a和d为指针。它实际上没有什么区别,它只是可读性。

Where both a and d are pointers. It actually makes no difference, it's just about readability.

其他人喜欢具有*旁边的类型,因为(除其他原因),他们认为这是一个指针为整数,并认为*所属的类型,而不是变量。

Other people like having the * next to the type, because (among other reasons) they consider it a "pointer to an integer" and think the * belongs with the type, not the variable.

就个人而言,我总是这样

Personally, I always do

Type *instance;

但它确实是你的,和你的公司/学校code风格指南。

But it really is up to you, and your company/school code style guidelines.

这篇关于在C中,什么是声明指针的正确语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆