Pointer code define style...

closed account (3CXz8vqX)
Right, I've seen pointers defined in three ways. Which way should I be using?

int* pointer;
int * pointer;
int *pointer

I'm also aware that (now) that a * changes the type because...as I just tried...
int ted = &andy is invalid until I make ted a pointer. (And I'm not entirely sure why...I'll just re-read this chapter...).

Whatever way you like, as they are all syntactically equivalent. Just be consistent.
i mostly like the first one.. because int is a pointer and attaching * closing to int makes more sense to me.

because pointers are made to store addresses and an int cannot hold an address.
In the interest of showing the other side, the counterargument is usually that style is misleading when declaring multiple variables separated by a comma (not a good idea in general, IMO) then only the first type has pointer type and so the * belongs with the identifier name.
Topic archived. No new replies allowed.