我们再来一次:int * n或int * n

编程入门 行业动态 更新时间:2024-10-25 23:32:27
本文介绍了我们再来一次:int * n或int * n的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我知道前者关于 后者的所有宗教论点,但有谁知道为什么Bjarne Stroustrup似乎更喜欢 int * n?愚蠢的问题,但我不得不问。

I''m aware of all the religious arguments of the former over the latter, but does anyone know why Bjarne Stroustrup seems to prefer int* n ? Dumb question, but I just had to ask.

推荐答案

5月29日下午5:20,Sal< h ... @ softcom。 netwrote: On May 29, 5:20 pm, Sal <h...@softcomwrote: 我知道前者对 后者的所有宗教论点,但是有谁知道为什么Bjarne Stroustrup似乎更喜欢 int * n?愚蠢的问题,但我只是要问。 I''m aware of all the religious arguments of the former over the latter, but does anyone know why Bjarne Stroustrup seems to prefer int* n ? Dumb question, but I just had to ask.

我个人更喜欢 int * n来表示指向整数的指针。 int& n表示对整数的引用。 & n表示n的地址。 * n表示取消引用名为n的指针。

Personally I prefer int * n to denote a pointer to an integer. int & n to denote a reference to an integer. &n to denote the address of n. *n to denote dereferencing of a pointer named n.

Sal写道: Sal wrote: 我知道前者对 $的所有宗教争论b $ b后者,但有谁知道为什么Bjarne Stroustrup似乎更喜欢 int * n?愚蠢的问题,但我只是要问。 I''m aware of all the religious arguments of the former over the latter, but does anyone know why Bjarne Stroustrup seems to prefer int* n ? Dumb question, but I just had to ask.

我不知道BS的推理,但我读了int * n。 asn是一个整数 指针。 " int * n"似乎说如果你取消引用n,你得到一个整数。 前者对我来说似乎更直观。 那个据说,Sutter和Alexandrescu的C ++编码标准第0项 说不要冒汗小东西。换句话说,不要太担心,这只是关于品味的问题。 Chris Gordon-Smith www.simsoup.info

Chris Gordon-Smith写道: Chris Gordon-Smith wrote: 我不知道BS的推理,但我读到了int * n。 asn是一个整数 指针。 " int * n"似乎说如果你取消引用n,你得到一个整数。 前者对我来说似乎更直观。 I don''t know BS''s reasoning, but I read "int* n" as "n is an integer pointer". "int *n" seems to say "If you dereference n, you get to an integer". The former seems more intuitive to me.

它可能更直观(也就是我使用的那个,因为这个原因), 但是这样想是这样的一个令人尴尬的问题: int * p1,p2; 有了这个想法,你也会认为你正在创造两个人/> 上面的指针,实际上你不是(你正在创建一个名为p1的 int指针和一个名为p2的int变量)。 纠正这一点仍然保持直觉并不容易。我个人通常做的只是避免问题并使用两行: int * p1; int * p2; 但是,它更详细。

It may be more intuitive (and is what I use as well, for that reason), but thinking about it like that causes an embarrassing problem: int* p1, p2; With that thinking you''d also think that you are creating two int-pointers above, when in fact you are not (you are creating an int-pointer named p1 and an int variable named p2). Correcting that while still keeping the intuition is not easy. What I personally usually do is to just avoid the problem and use two lines: int* p1; int* p2; It''s more verbose, though.

更多推荐

我们再来一次:int * n或int * n

本文发布于:2023-11-30 20:22:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1651370.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:再来一次   int

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!