[ / / / / / / / / / / / / / ] [ dir / random / 93 / biohzrd / hkacade / hkpnd / tct / utd / uy / yebalnia ]

/g/ - Technology

Make /g/ Great Again

Name
Email
Subject
REC
STOP
Comment *
File
Password (Randomized for file and post deletion; you may also set your own.)
Archive
* = required field[▶Show post options & limits]
Confused? See the FAQ.
Embed
(replaces files and can be used instead)
Options
dicesidesmodifier

Allowed file types:jpg, jpeg, gif, png, webp,webm, mp4, mov, swf, pdf
Max filesize is16 MB.
Max image dimensions are15000 x15000.
You may upload5 per post.


File: 9cda192ee46e4b9⋯.jpg (56.42 KB,528x492,44:41,1243632632.jpg)

 No.12984

int* foo = NULL;

vs

int *foo = NULL;

Why do some people think that the * belongs to 'foo' instead of 'int'? The type of foo is not int, it's a pointer, the value it has is a memory address, so clearly the * is part of the type. foo is not even defined, it's NULL which makes sense for a pointer, but not for an int.

In fact I think the most logical syntax would be "*int foo = NULL;".

____________________________
Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

 No.12988

I thought about this before, its due to list declarations.

int* nigger, please; -> implies two pointers

int *nigger, *please; -> probably what you meant

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

 No.12990

>>12984

>in the absolutely rare cases of this:

>int* a, b

>a is a pointer, b is not a pointer

>ideally int *a, *b

not a huge deal, int* is fine but just be wary of that circumstance

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

 No.12993

>>12988

>>12990

I see, I very rarely declare multiple variables in one line like that let alone multiple pointers. Usually I have a struct for 2 closely related variables anyway, for example positions/dimensions.

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

 No.13020

>>12984

>int *foo = NULL;

This is the correct way to format it. You should think about the statement as reading "the dereferenced type *foo is an integer." Then declarations like

int *foo, bar;

make sense, because both *foo and bar are integer types.

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.



[Return][Go to top][Catalog][Nerve Center][Random][Post a Reply]
Delete Post [ ]
[]
[ / / / / / / / / / / / / / ] [ dir / random / 93 / biohzrd / hkacade / hkpnd / tct / utd / uy / yebalnia ]