garbage?
If you haven't initialised array elements or incorrectly declared an array the data in it will be the data that was in the memory spots before the array even existed.
If you change it you can cause the computer to crash...
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
int numbers[5]; // array
char *str; // input string
for(int i = 0; i < 5; i++) // goes from 0 to 4 (as arrays start at 0)
{
cout << "Enter number " << i << " for the array";
cin >> str;
data = atoi(str);
numbers[i] = data;
}
That's not a string -- you just did a Bad Thing.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
when using C++ you should never use char* for strings, instead use which yields the string class.
You can then convert those to char* where needed.
I agree that char* is usually a better idea than char[] to handle strings in C.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337