-2

I Just want to know what is the difference between the following way of assigning a pointer. i was watching a C tutorial online and couldn't understand why he used the second pointer like this char * buffer;. Instead of char *buffer

Like the way I use the pointer in all my C learning. is it style? e.g

FILE *pFile;

struct product *next;

does it matter where you put the asterix (pointer) or what is the meaning behind it?

Madona wambua
  • 1,408
  • 1
  • 21
  • 37

1 Answers1

1

Nope, there is no difference, it's a matter of preference.

I tend to put it as struct product* next because it makes it clearer that the type of next is product*, AKA a pointer to a product. But different people advocate different things.

nameless912
  • 367
  • 1
  • 12
  • This might be confusing, when you declare multiple variables at once. For instance, with declaration as: `struct product* next, next_second;`, second variable is of type `struct product`, not pointer to it. – Grzegorz Szpetkowski Aug 01 '15 at 18:15
  • That's true, but this is also terrible practice in my opinion no matter how you do it, it's just really terribly opaque. – nameless912 Aug 02 '15 at 15:09