将 * 星号放在 Objective C 指针变量的何处 [英] Where to put the * Asterisk on Objective C Pointer Variables

查看:44
本文介绍了将 * 星号放在 Objective C 指针变量的何处的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是一个简单的问题 - 之间有什么区别(如果有的话):

Just a quick question - what is the difference (if any) between:

NSObject* myObj

NSObject *myObj

甚至

NSObject * myObj

?

推荐答案

从技术角度来看,这无关紧要.

From a technical point of view, it doesn't matter.

我个人使用最后一个选项(中间的 *),但这取决于个人喜好.

Personally I use the last option (* in the middle), but it's a matter of personal taste.

一个极端情况是多个内联声明的定义,比如

A corner case would be the definition of multiple inline declarations, like

NSObject *a, b

相对于

NSObject *a, *b

第一种情况会产生一个指向 NSObject 的指针和一个 NSObject(这当然是禁止的,它不会编译),而第二种情况会产生两个指针.

The first case will produce a pointer to NSObject and a NSObject (which of course is forbidden and it wouldn't compile), whereas the second one will produce two pointers.

这篇关于将 * 星号放在 Objective C 指针变量的何处的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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