char *p = "this"; | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

char *p = "this";

Isn't this declaration wrong? "&" should come before "this" as p is a pointer???

3rd Jul 2017, 3:15 PM
Kushagra Agarwal
Kushagra Agarwal - avatar
2 Answers
+ 5
if "this" was a value of some variable, then yes *p would need to be assigned to the reference of that variable i.e: // Pointers job is to hold a value // in this case it has to de-reference &myVar char myVar = 'a'; char *p = &myVar; // in your case, you have no variable assigned // and since pointers hold usual values (abc,123 etc) // it is allowed to do: char *p = 'a';
3rd Jul 2017, 3:45 PM
Nedim Kanat
Nedim Kanat - avatar
- 1
'this' is a pointer
3rd Jul 2017, 3:20 PM
Jojo