#include <iostream>
int main( )
{
char name[ ] = "Hello" ; // | 'H' | 'e' | 'l' | 'l' | 'o' | '/0' |
// name is an array of six chars
// &name is the address of the array of six chars
std:: cout << & name << '\n ' ;
const char * pc = & ( name[ 0 ] ) ;
// pc is a pointer to the char at position zero ('H')
// prints out the null terminated c-string "Hello"
std:: cout << pc << '\n ' ;
const void * pv = pc ;
// pv contains the address pc (address of the char at position zero)
// prints out the address of char 'H' in the array
std:: cout << pv << '\n ' ;
// print out every char in the array along with its address
for ( int i = 0 ; i < sizeof ( name) ; ++ i )
{
char c = name[ i] ;
const void * pv = & ( name[ i] ) ;
if ( c ! = 0 ) std:: cout << "char " << c << " is at address " << pv << '\n ' ;
else std:: cout << "null charater is at address " << pv << '\n ' ;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKaW50IG1haW4oKQp7CiAgICBjaGFyIG5hbWVbXSA9ICJIZWxsbyIgOyAvLyB8ICdIJyB8ICdlJyB8ICdsJyB8ICdsJyB8ICdvJyB8ICcvMCcgfAogICAgLy8gbmFtZSBpcyBhbiBhcnJheSBvZiBzaXggY2hhcnMKCiAgICAvLyAmbmFtZSBpcyB0aGUgYWRkcmVzcyBvZiB0aGUgYXJyYXkgb2Ygc2l4IGNoYXJzCiAgICBzdGQ6OmNvdXQgPDwgJm5hbWUgPDwgJ1xuJyA7CgogICAgY29uc3QgY2hhciogcGMgPSAmKCBuYW1lWzBdICkgOwogICAgLy8gcGMgaXMgYSBwb2ludGVyIHRvIHRoZSBjaGFyIGF0IHBvc2l0aW9uIHplcm8gKCdIJykKCiAgICAvLyBwcmludHMgb3V0IHRoZSBudWxsIHRlcm1pbmF0ZWQgYy1zdHJpbmcgIkhlbGxvIgogICAgc3RkOjpjb3V0IDw8IHBjIDw8ICdcbicgOwoKICAgIGNvbnN0IHZvaWQqIHB2ID0gcGMgOwogICAgLy8gcHYgY29udGFpbnMgdGhlIGFkZHJlc3MgcGMgKGFkZHJlc3Mgb2YgdGhlIGNoYXIgYXQgc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