0
#include<stdio.h>

#define KOREA "대한민국"

char* My_strcpy(char* dest, const char* src);

What is the difference between "char* p" and "char *p"?

halfer
  • 19,824
  • 17
  • 99
  • 186
이동준
  • 25
  • 1
  • 5

3 Answers3

2

There is no difference, it is only a matter of style.

Like John Skeet wrote in a former comment (for another topic):

Different people have different conventions for that.

wake-0
  • 3,918
  • 5
  • 28
  • 45
2

char* p and char *p are exactly equivalent.

In many ways, you ought to write char *p since, really, p is a pointer to char. But as the years have ticked by, most folk regard char* as the type for p, so char* p is possibly more common.

But do note though that char* p, q; actually declares p as a pointer to a char and q as a char! If you wanted two pointers, you would have to write char *p, *q; or the incredibly obfuscated

char* p, *q;.

Bathsheba
  • 231,907
  • 34
  • 361
  • 483
  • I feel declaring p and q on separate lines is a better deal - `char *p; char *q;` just to avoid any confusion related to placement of asterisk. But this is just a one time confusion it seems until one gets to know the basics of pointer declaration semantics. – RBT Oct 29 '16 at 02:28
1

char* p and char *p are the same. As is char*p and char * p.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • Thank you for mentioning `char*p and char * p`. I've never used them :). I've always been using the other two. – RBT Oct 29 '16 at 02:18