2

i'm a beginner in C , so i'm a little confused if char* ft_name(args) is equivalent to char *ft_name(args) in function prototype .

can anybody help me please

Ismail El Moudni
  • 622
  • 2
  • 9
  • 19
  • 1
    What kind of an answer do you need? Assuming that "Yes." would not satisfy you. – Yunnosch Aug 11 '18 at 11:50
  • Possible duplicate of [What makes more sense - char\* string or char \*string?](https://stackoverflow.com/questions/558474/what-makes-more-sense-char-string-or-char-string) – Achal Aug 11 '18 at 12:02
  • 1
    @IsmailElMoudni The more general point is that in *any* declaration involving pointers, whether it's a simple char pointer or an elaborate function prototype, it doesn't make a difference where you put the whitespace. – Steve Summit Aug 11 '18 at 12:12
  • @IsmailElMoudni Hmm. Not sure what you mean. Of course `char* p1, p2` does *not* declare multiple pointers at once! – Steve Summit Aug 11 '18 at 12:35
  • I agree with @SteveSummit above. Furthermore, to read pointer declarations, one needs to read them from right to left, with each asterisk `*` as "a pointer to". So, `char *const p` reads *"p is a const pointer to char"*, and `const char *p` reads *"p is a pointer to const char."*. Because `*` is associated with the variable and not the type in declarations, `char *p, c;` makes more sense (and declares `p` to be a pointer to char, and `c` a char). – Nominal Animal Aug 11 '18 at 21:25

2 Answers2

5

C compiler ignores the white space between the tokens and both declrations from the compiler point of view look like

char*ft_name(args);

so they are exactly the same.

the only place where compiler does not ignore the white space are string literals like "Hello world"

The program:

int main(int argc, char *    
*      argv)
{
    size_t       s = 
                     strlen(argv    [   0]   );   
    printf("%zu %s\n", 
                s,    argv
                [
                    0
                ]);
}

is seen by the compiler as

int main(int argc,char**argv){size_t s=strlen(argv[0]);printf("%zu %s\n",s,argv[0]);}

White space is not ignored during the preprocessor stage when macros are expanded.

0___________
  • 60,014
  • 4
  • 34
  • 74
  • Another place where whitespace is significant is in expressions like `a = b - -c` (or `b-- - --c` :-) ). Take all the whitespace out, and it doesn't work. Another cute example is `d = e / *p`. – Steve Summit Aug 12 '18 at 15:07
  • @SteveSummit I wrote `C compiler ignores the white space between the tokens` and I think it is easy to understand that white space separating tokens is not ignored and it used to separate them. So your examples are not good here. Same as whitespaces in my example : `size_t s` space is needed to separate two tokens – 0___________ Aug 12 '18 at 17:12
3

Yes.

char* ft_name(args)

and

char *ft_name(args)

are equivalent.

gsamaras
  • 71,951
  • 46
  • 188
  • 305