When declaring a string in C what is the difference between
char* mystring;
and
char *mystring;
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is no difference. The second option is commonly preferred because it makes it easier to avoid this pitfall:
Here,
str1is achar*butstr2is a plainchar. The other way of writing the declaration makes it easier to see that you have to put an extra asterisk in there:Now both variables are of type
char*.