Click here to Skip to main content
15,888,238 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,

What is the difference between:

char* f(){}

and
char *f(){}


When i will get the value from where i called the above functions what would the syntax be?

char *buffer=f();

OR
char* buffer=f();


I googled it out but dint find a satisfying answer.And what is the difference between the above syntaxes.

Thanks and Regards,
Rahul
Posted

In short because C is a free format language, whatever style you choose its ok while the parser can make a distinction of each token.
Please consider that in your case even:
C++
char*f(){}

It's perfectly equivalent top the other 2.
This peculiarity of C lead to a very special type of contest called C obfuscation contest[^]. This site will give you much more answers that all other links together... ;-)
 
Share this answer
 
See http://www.cdecl.org/[^] and play with your declarations (without the function body).

See also In C, what is the correct syntax for declaring pointers?[^].

BTW: I wonder if you were lazy or what - this is one of the first hits when I enter your question in Google...

Cheers
Andi
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 4-Jun-15 17:09pm    
5ed. At first I would think that first link is a bit of off-topic, but later on I realized that the declaration can be edited. Nice.
Basically, people answered the question.
—SA
Andreas Gieriet 5-Jun-15 3:18am    
Thanks for your 5!
The first link allows to play with the declaration syntax, that's why I thought it would be useful.
Cheers
Andi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900