0

What is the difference between int* ptr; and int *ptr;?

I am doing a C++ linked list project, and I wish to know the difference between the two statements above.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • 3
    No difference whatsoever, they are treated exactly the same. Whitespace between tokens is ignored. – Remy Lebeau Jun 08 '20 at 23:55
  • The only difference is the whitespace. You forgot a version: `int * ptr;`. – Thomas Matthews Jun 08 '20 at 23:56
  • Whitespace doesn't matter in C++. As long as tokens are separated properly you can have any amount of whitespace and it won't affect your program behavior. – eesiraed Jun 08 '20 at 23:57
  • hmm that is weird. When doing my c++ project an error message was thrown when i used something similiar to "int *ptr" and not "int* ptr" this is not the exact code so there may lie my issue. Thank you for the quick responses. – samschafer77 Jun 08 '20 at 23:59
  • You can even have `int` and `*` and `ptr` and `;` on separate lines. – Eljay Jun 09 '20 at 00:16

0 Answers0