r/C_Programming • • Jul 28 '26

Does anyone else dislike pointer declaration?

For reference I am a fourth year computer engineering student. C is my preferred language.

Pointers are declared like this usually:

int *ptr_to_int;

Where the asterisk means it is a “pointer to” the specified type. The asterisk is placed immediately preceding the variable name, with no white peace.

This is what does not make sense to me. I feel that:

int* ptr_to_int;

Is far more clear. The way I see it, the asterisk modifies the type, so therefore it belongs next to the type. Putting it next to the variable name makes me think it is some kind of action or modification to the variable itself.

I think that when using * and & in code, it makes sense to apply it in front of the variable name:

int value = 3;
ptr_to_value = &value;
int copied_value = *ptr_to_value;

It is clear here that syntactically, the * represents something more like an action than a label.

Why is the convention to place the asterisk near variable name, not type? L

65 Upvotes

142 comments sorted by

View all comments

Show parent comment

1

u/kat-tricks Jul 29 '26 edited Jul 29 '26

`define @ *`
edit: god i cannot get code formatting to work here, i hope it is clear enough. Dug through settings three times to fail to find the markdown editor

1

u/EmbedSoftwareEng Jul 29 '26

See the Aa in the lower left corner of the editor? Click that and a tool bar will appear above.

Clicking the </> tool will start a code fragment inline with other text. Clicking it a second time closes the inline code fragment.

Clicking the square with the </> in the upper left corner starts a new code block.

Hitting Return three times will break out of it and return to normal text.

1

u/kat-tricks Jul 30 '26

huh, i don't have that button. Maybe i need to update or something