I’m new to C and I’m wondering what the difference is between these two:
char* name;
struct book *abook;
I know the struct constructs a book, but with the char how come the * is place before the variable name?
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.
TYPE * variableName, TYPE* variableName and TYPE *variableName are all syntactically the same. It’s a matter of notation how you use them.
Personally I prefer the last form. It’s simply because the star operator works on the token to the right of it. In a declaration like
only foo is a pointer but not bar. Therefore it looks more logical to put the star right next to the variable name.