FW: why it is not from 0?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dear gcc/g++ programers:
  a simple c++ program
copied from book
, show it array index and pointer address and contecnt
my ouput in my system is the same as book indicate, but I don't know why (and like to know why)
the content of array[index] is from 30 rather from 0

looking to see any advancer's opinion
Eric


> Subject: why it is not from 0?
>
> root@eric-laptop:/home/eric/practicalCpp# ./a.out
> &array[index]=0x804a034 (array+index)=0x804a034 array[index]=0x30
> &array[index]=0x804a035 (array+index)=0x804a035 array[index]=0x31
> &array[index]=0x804a036 (array+index)=0x804a036 array[index]=0x32
> &array[index]=0x804a037 (array+index)=0x804a037 array[index]=0x33
> &array[index]=0x804a038 (array+index)=0x804a038 array[index]=0x34
> &array[index]=0x804a039 (array+index)=0x804a039 array[index]=0x35
> &array[index]=0x804a03a (array+index)=0x804a03a array[index]=0x36
> &array[index]=0x804a03b (array+index)=0x804a03b array[index]=0x37
> &array[index]=0x804a03c (array+index)=0x804a03c array[index]=0x38
> &array[index]=0x804a03d (array+index)=0x804a03d array[index]=0x0
> root@eric-laptop:/home/eric/practicalCpp# cat array-p.cpp
> #include 
> #include 
> #include 
>
> const int ARRAY_SIZE = 10; // Number of characters in array
> // Array to print
> char array[ARRAY_SIZE] = "012345678";
>
> int main()
> {
> int index; /* Index into the array */
>
> for (index = 0; index < ARRAY_SIZE; ++ index) {
> std::cout << std::hex; // Trick to print hex numbers
> assert(index >= 0);
> assert(index < sizeof(array)/sizeof(array[0]));
> std::cout <<
> "&array[index]=0x" <<
> reinterpret_cast(&array[index]) <<
>
> " (array+index)=0x" <<
> reinterpret_cast(array+index) <<
>
> " array[index]=0x" <<
> static_cast(array[index]) << '\n',
> std::cout << std::dec; // Another trick to go back to decimal
> }
> return (0);
> }
> root@eric-laptop:/home/eric/practicalCpp#
 		 	   		  



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux