I’m playing with pointers and a can’t get why this declaration is fine
char *ptr = "Hey"
but this is wrong
int *ptr = 10;
Can any one explain ?
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.
The correct analogy would be that the following two are both wrong:
Here you are trying to assign a value of some type to a variable that is a pointer to a variable of that type.
By contrast, the following are correct:
The string literal
"hello"is an anonymous, read-only array of characters, of identical content astmp_b, so it can be interpreted as a pointer to its first element. Since the character data is read-only, the correct definition should be this: