+ 1
char *p = "this";
Isn't this declaration wrong? "&" should come before "this" as p is a pointer???
2 Réponses
+ 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';
- 1
'this' is a pointer