I think that this is a fairly simple question… I’ve tried finding the specifics and can’t. The code:
#include <iostream>
using namespace std;
int main() {
char * veggie_burger = "delicious";
cout<<endl<<veggie_burger<<endl;
for (int count = 0; count < 9; count++){
cout<<veggie_burger[count]
<<" @: "
<<&veggie_burger[count]
<<endl;
}
cout<<&veggie_burger;
return 0;
}
this will output
delicious
d @ delicious
e @ elicious
l @ licious
i @
icious
c @ cious
i @ ious
o @ ous
u @ us
s @ s
001DF7D4 (or wherever)]
What exactly is the difference between &veggie_burger[n] and &veggie_burger? Shouldn’t the pointer be pointing to the place in memory where &veggie_burger[3] stores ‘l’ and not start the sequence of characters at ‘l’?
veggie_burger[n]is exactly the same as*(veggie_burger+n), so&veggie_burger[n]meansveggie_burger + n, or a pointer to thenth character. It has typechar*, because it is the address of a character.&veggie_burger, on the other hand, is the address of the pointer. It has typechar **.