Solved Best syntax for pointer declaration?

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

How do you usually declare pointers?


  • Total voters
    8

Lovelace

Jr.Coder
Full Member
Nobleman
Oct 23, 2015
83
938
5
I'm not sure if this had been discussed before in this forum. I was just wondering how most people would declare a pointer type variable.
 

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,073
78,998
2,371
I used to do "void * ptr;" but now I do void* ptr cuz it makes more sense to me idk
 
Last edited:

Liduen

Hacker
Dank Tier VIP
May 19, 2013
702
8,478
33
For me the * goes with the type when declaring a pointer, because obviously it is part of the type not part of the variable identifier.
It makes more sense this way and the other way is also the reason why many beginners have problems understanding the functionality of the * operator.

This bugged me for so long it itches everytime I see the "void *name" way.
 

PwndDepot

I has a status
Dank Tier VIP
Trump Tier Donator
Dank Tier Donator
Nov 5, 2014
239
7,748
19
For me the * goes with the type when declaring a pointer, because obviously it is part of the type not part of the variable identifier.
It makes more sense this way and the other way is also the reason why many beginners have problems understanding the functionality of the * operator.

This bugged me for so long it itches everytime I see the "void *name" way.
My thoughts exactly. It still bugs me everytime I see anything different.
 

Lukor

ded
Meme Tier VIP
Fleep Tier Donator
Dec 13, 2013
488
5,353
25
Sorry Liduen...
I still do the type *ptr

I may change this in the future as i never thought about
because obviously it is part of the type not part of the variable identifier
 

Lovelace

Jr.Coder
Full Member
Nobleman
Oct 23, 2015
83
938
5
Somehow placing the dereference operator beside the variable name seems to make more sense though.
 

Luciz

Coder
Dank Tier Donator
Nobleman
Jul 10, 2014
101
458
3
For me the * goes with the type when declaring a pointer, because obviously it is part of the type not part of the variable identifier.
It makes more sense this way and the other way is also the reason why many beginners have problems understanding the functionality of the * operator.

This bugged me for so long it itches everytime I see the "void *name" way.
Yea I feel the same.

What kinda sucks though is when declaring multiple variables you need the * for each variable. So I think the correct way is actually the one we both seem to dislike, haha.
 

Lovelace

Jr.Coder
Full Member
Nobleman
Oct 23, 2015
83
938
5
Yea I feel the same.

What kinda sucks though is when declaring multiple variables you need the * for each variable. So I think the correct way is actually the one we both seem to dislike, haha.
It's actually a bad practice to declare variables on a single line. Visualize it as something like this:

C++:
if ((var = foo()) == 0)
{
	// do something
}
Most people would prefer the deference operator (*) to be a part of the data type and declaring multiple variables on a single line ruins the expectation of novice programmers of having declared multiple pointer type variables.

C++:
int* a, b, c;
Obviously the compiler reads this as:

C++:
int* a;
int b;
int c;
 

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,073
78,998
2,371
but standard reference syntax is int &variable
now that's a mind f00000000ck
 
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Similar threads

Community Mods