fork(3) download
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5. char name[] = "Hello" ; // | 'H' | 'e' | 'l' | 'l' | 'o' | '/0' |
  6. // name is an array of six chars
  7.  
  8. // &name is the address of the array of six chars
  9. std::cout << &name << '\n' ;
  10.  
  11. const char* pc = &( name[0] ) ;
  12. // pc is a pointer to the char at position zero ('H')
  13.  
  14. // prints out the null terminated c-string "Hello"
  15. std::cout << pc << '\n' ;
  16.  
  17. const void* pv = pc ;
  18. // pv contains the address pc (address of the char at position zero)
  19.  
  20. // prints out the address of char 'H' in the array
  21. std::cout << pv << '\n' ;
  22.  
  23. // print out every char in the array along with its address
  24. for( int i = 0 ; i < sizeof(name) ; ++i )
  25. {
  26. char c = name[i] ;
  27. const void* pv = &( name[i] ) ;
  28. if( c != 0 ) std::cout << "char " << c << " is at address " << pv << '\n' ;
  29. else std::cout << "null charater is at address " << pv << '\n' ;
  30. }
  31. }
  32.  
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
0xbfacceca
Hello
0xbfacceca
char H is at address 0xbfacceca
char e is at address 0xbfaccecb
char l is at address 0xbfaccecc
char l is at address 0xbfaccecd
char o is at address 0xbfaccece
null charater is at address 0xbfaccecf