Original Post
Hi,
Using the code snippet at the bottom of this post, can somebody tell me the following...
1) Why is there a size difference between c5 and st?
2) When dispaying the contents of c5 why do I get garbage values from further down the memory?
3) Why can I access undeclared indexes of c5.
Just in case...
I'm using a PIII Pentium 450 with 256MBRAM
with DEV-C++ (Bloodshed).
the output I get on my pc is:
char array = 5
string = 4
HelloE x
HelloE
Hello
Press any key to continue . . .
Thanks!
Edited by - Whisk on January 1, 2002 9:43:20 PM
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
char c5[5] = { 'H', 'e', 'l', 'l', 'o' };
string st = "Hello";
cout << "char array = " << sizeof(c5)
<< "\nstring = " << sizeof(st)
<< endl << endl
<< c5[0] << c5[1] << c5[2] << c5[3]
<< c5[4] << c5[5] << c5[6] << c5[7]
<< endl << c5
<< endl << st
<< endl;
system("PAUSE");
return 0;
}
|