public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* FW: why it is not from 0?
       [not found] <ED91C896BC086A247AE49F5983AD96D0@ericlin.fsshl.zzn.com>
@ 2011-05-29 11:51 ` Eric Lin
  2011-05-29 13:19   ` bjorn rohde jensen
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Lin @ 2011-05-29 11:51 UTC (permalink / raw)
  To: gcc-help


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#
 		 	   		  

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: FW: why it is not from 0?
  2011-05-29 11:51 ` FW: why it is not from 0? Eric Lin
@ 2011-05-29 13:19   ` bjorn rohde jensen
  0 siblings, 0 replies; 2+ messages in thread
From: bjorn rohde jensen @ 2011-05-29 13:19 UTC (permalink / raw)
  To: gcc-help

Hi Eric,

This is really a question about character sets and string representation
in C and not a question about GCC.

What you are seeing are the integer values of the individual characters
in the array, that is '0' to '8' followed by the string terminator '\0'.
The values, you see, are consistent with with the ASCII character set.

http://en.wikipedia.org/wiki/ASCII

Try changing the string and compare the result with the ASCII tables.

Yours sincerely,

Bjorn

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-05-28  8:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <ED91C896BC086A247AE49F5983AD96D0@ericlin.fsshl.zzn.com>
2011-05-29 11:51 ` FW: why it is not from 0? Eric Lin
2011-05-29 13:19   ` bjorn rohde jensen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).