The type of left and right is node* so like other types they should be declared as node* left,right; Example int a,b;
Asked
Active
Viewed 515 times
-3
-
2So that you can write `int a, *b = &a`. – Maxim Egorushkin Jun 21 '17 at 17:24
-
7How did this get +3 ?? – Eugene Sh. Jun 21 '17 at 17:24
-
Because the standard says so. Are you interested in the history behind this syntax decision? – Daniel Jour Jun 21 '17 at 17:24
-
because the pointer somehow belongs to the variable, so it should be specified as: `int *left, *right, nopointer_just_int` – Gizmo Jun 21 '17 at 17:24
-
`node* left, right;` is same as `node *left, *right;` throught first one prefered. read a book first, its basic. – roottraveller Jun 21 '17 at 17:25
-
1@rootTraveller, can you back up that assertion? – Toby Speight Jun 21 '17 at 17:26
-
1@rootTraveller Are you sure? – Eugene Sh. Jun 21 '17 at 17:26
-
Variable declaration syntax is not `typename varname1, varname2`. The type information doesn't all go in one block on the left. (Arguably, it should have; C variable declaration syntax is confusing.) – user2357112 Jun 21 '17 at 17:26
-
5@rootTraveller That is 100% wrong. `node* left, right;` is the same as `node* left; node right;` – NathanOliver Jun 21 '17 at 17:27
-
@NathanOliver I did not get it, would you share some links ? – roottraveller Jun 21 '17 at 17:29
-
1@rootTraveller Just look at the answers on the question this is closed as a duplicate of. – NathanOliver Jun 21 '17 at 17:30
-
@NathanOliver `node* left, right;` from here how do you guys getting this `node right;`??? – roottraveller Jun 21 '17 at 17:31
-
2@rootTraveller Would this link be good enough: https://ideone.com/sI2j2v ? – Eugene Sh. Jun 21 '17 at 17:31
-
And the reason for spamming tags of two different languages is? – too honest for this site Jun 21 '17 at 17:31
-
@rootTraveller The pointer is attached to the variable name, not the type name. In `node* left, right;` `right` is not a pointer. That's just how pointers and references work. – NathanOliver Jun 21 '17 at 17:32
-
1@rootTraveller read a [good book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) please. – Jesper Juhl Jun 21 '17 at 17:33
-
@EugeneSh. I got it. – roottraveller Jun 21 '17 at 17:34
2 Answers
1
You have to pick one way or the other, and this way is less awful. For an example of how awful the other way would be, compare:
int a[10], b[20], c[30];
to
int[10] a;
int[20] b;
int[30] c;

David Schwartz
- 179,497
- 17
- 214
- 278
-
3
-
True, but the point is that it's a choice between two schemes that each have their advantages and disadvantages. – David Schwartz Jun 21 '17 at 17:29
-
2
-
@NathanOliver That's how you'd declare an array if the rule was the one the OP suggests. Just like `int* a, b;` instead of `int *a, *b;` you'd have `int[10] a, b;` instead of `int a[10], b[10];`. Unless you're suggesting something even more bizarre. – David Schwartz Jun 21 '17 at 17:47
-
@DavidSchwartz Oh. I didn't get that you were showing how it would look if it was attached to the type. – NathanOliver Jun 21 '17 at 17:48
0
When programming in C, if you get in the habit of attaching the * to the variable names it will make more sense to you.
int *i,j;
i is an int* and j is an int.

cleblanc
- 3,678
- 1
- 13
- 16