c++ - pointers and char arrays -



c++ - pointers and char arrays -

i think simple question... i've tried finding specifics , can't. code:

#include <iostream> using namespace std; int main() { char * veggie_burger = "delicious"; cout<<endl<<veggie_burger<<endl; (int count = 0; count < 9; count++){ cout<<veggie_burger[count] <<" @: " <<&veggie_burger[count] <<endl; } cout<<&veggie_burger; homecoming 0; }

this output

delicious d @ delicious e @ elicious l @ licious @ icious c @ cious @ ious o @ ous u @ us s @ s 001df7d4 (or wherever)]

what difference between &veggie_burger[n] , &veggie_burger? shouldn't pointer pointing place in memory &veggie_burger[3] stores 'l' , not start sequence of characters @ 'l'?

veggie_burger[n] same *(veggie_burger+n), &veggie_burger[n] means veggie_burger + n, or pointer nth character. has type char*, because address of character.

&veggie_burger, on other hand, address of pointer. has type char **.

c++ arrays pointers

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -