Today I've learned some concepts about Pointer in C++ and I have a confusion in this code snippet and its result.
Source Code:
// Pointer array
#include <iostream>
using namespace std;
void main () {
char * say = "Hello";
//
cout << "say = " << say << endl;
cout << "&say = " << &say << endl;
cout << "*say = " << *say << endl;
cout << "say[1]=" << say[1] << endl;
cout << "*(say+1)=" << *(say+1) << endl;
//
cout << endl << endl;
for (int i=0; i<5; i++) {
cout << "say["<< i <<"]=" << say[i] << endl;
}
//
cout << endl << endl;
[B]for (int i=0; i<5; i++) {
cout << "&say["<< i <<"]=" << &say[i] << endl;
}[/B]
}
And this is the result:
say = Hello
&say = 0012F3A4
*say = H
say[1]=e
*(say+1)=e
say[0]=H
say[1]=e
say[2]=l
say[3]=l
say[4]=o
[B]&say[0]=Hello
&say[1]=ello
&say[2]=llo
&say[3]=lo
&say[4]=o[/B]
I try to understand why it gave this result, but I cannot understand the section in bold.
Please explain it for me.
Thanks very much,
Nichya.