-4

I'm trying to understand if there is any difference between:

bool String_Init(String *str, char * s, uint32_t len){};

and

bool String_Init(String *str, char *s, uint32_t len){};

Also,

const char * String_GetCString(const String * const str){};

and

const char *String_GetCString(const String * const str){};

Thank you!

Gustavo
  • 43
  • 1
  • 7
  • Each pair are identical, first two and last two. Spaces does nothing. – Maroun Dec 10 '14 at 11:56
  • I would flag it but the duplicate search is useless. I know it exists but I can't find it. – 2501 Dec 10 '14 at 11:56
  • @MarounMaroun Except the whitespace between the `*` and the parameter name, that's what confuses the OP I guess... – nouney Dec 10 '14 at 11:57
  • I wasn't able to find a similar question to mine. Most ppl were trying to understand pointers. – Gustavo Dec 10 '14 at 11:58
  • I have no idea why ppl are down voting this. Seriously, read the darn question before you down vote. I searched and found nothing. – Gustavo Dec 10 '14 at 12:03
  • Instead of asking all these incredibly basic questions, why don't you look it up in your C book? Or Google? – Lundin Dec 10 '14 at 12:10
  • But you see mr @Lundin. That duplicate is different. They are talking about variables. I'm talking about functions. I'm new to C so I wouldn't know if the function and variable would be the same. – Gustavo Dec 10 '14 at 12:14
  • It is the very same thing. Function parameters are variables. – Lundin Dec 10 '14 at 12:21

2 Answers2

2

As explained in more detail here, for any type T, the expression T* means 'pointer to T'. It does not matter whether the asterisk is put to the argument name in the function name or to the type name for which the pointer type is referred to. The argument declarations T* arg and T *arg are identical.

Codor
  • 17,447
  • 9
  • 29
  • 56
1

There is no differecne in the code pairs you've shown. They are same.

  • char *s
  • char * s
  • char* s

all are same. Most of the time extra whitespace(s) is(are) ignored in c.

To clear your confusion, in case of

char *s

the * should be read as a part of the data type, it is not a part of the variable name.

IMHO, to avoid confusion , better to write char * s;

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261