Tech Lead/Team Lead. Senior WebDev.
Intermediate Grade on Computer Systems-
High Grade on Web Application Development-
MBA (+Marketing+HHRR).
Studied a bit of law, economics and design
Location
Spain
Education
Higher Level Education Certificate on Web Application Development
You can also understand the asterisk as a prefix on the name to determine that int *x as X is a pointer storing a memory address of type int data or any other argument of your preference. That's the issue, that you can read and interpret it in different ways so it's a bit subjective... 😅
I understand that sometimes the notation is confusing, because different textbooks place the * differently. The three following declarations are equivalent:
int*x;int*x;int*x;
I always believed that the least confusing notation is int * x because when read from right to left you can interpret it as x is a pointer, hence allocating a memory address which references to an int value, plus you not "link" visibly the asterisk to the type nor to the var name.
There are some details into that, see:
int*x,y,z;
This is 1 pointer and 2 int variables.
int*x,y,z;
This is still 1 pointer and 2 int variables.
For the sake of clarity:
int*x,*y,*z;
Those are effectively 3 pointers and we can understand the asterisk as a somewhat independent (keyword if you will) and use it just like that.
I haven't coded in C for around 10Y, maybe nowadays there is some linter out there that you can use to enforce one way or the other in your projects 😁
Tech Lead/Team Lead. Senior WebDev.
Intermediate Grade on Computer Systems-
High Grade on Web Application Development-
MBA (+Marketing+HHRR).
Studied a bit of law, economics and design
Location
Spain
Education
Higher Level Education Certificate on Web Application Development
Tech Lead/Team Lead. Senior WebDev.
Intermediate Grade on Computer Systems-
High Grade on Web Application Development-
MBA (+Marketing+HHRR).
Studied a bit of law, economics and design
Location
Spain
Education
Higher Level Education Certificate on Web Application Development
You can also understand the asterisk as a prefix on the name to determine that
int *xasX is a pointer storing a memory address of type int dataor any other argument of your preference. That's the issue, that you can read and interpret it in different ways so it's a bit subjective... 😅I understand that sometimes the notation is confusing, because different textbooks place the * differently. The three following declarations are equivalent:
I always believed that the least confusing notation is
int * xbecause when read from right to left you can interpret it asx is a pointer, hence allocating a memory address which references to an int value, plus you not "link" visibly the asterisk to the type nor to the var name.There are some details into that, see:
This is 1 pointer and 2 int variables.
This is still 1 pointer and 2 int variables.
For the sake of clarity:
Those are effectively 3 pointers and we can understand the asterisk as a somewhat independent (keyword if you will) and use it just like that.
I haven't coded in C for around 10Y, maybe nowadays there is some linter out there that you can use to enforce one way or the other in your projects 😁
Thank you for engaging in good faith.
I completely disagree with everything you said.
Apart from the bit about linters. Linters are great.
😂😂 you are truly angry around this topic I see.
I updated the comment above with a bit more of information around why I think that
int * xis the least confusing, please check it.I don't think I'll be able to stress it further, though 😅
PD: Just in case it's not clear in the text above I agree with you in that
int* xis the worse way by far.Between the other two:
it's just subjective opinion around readability and I won't care much if it's one or the other.