For displaying arrays you do not just call the array its self you have to make a for() loop to output.
for(int i = 0; i < 8; i++)
{
cout << arr[i];
}
sfuo
Practically a Master Poster
656 posts since Jul 2009
Reputation Points: 164
Solved Threads: 99
also you have not terminated the array with a newline value so cout does not know where the end oh the char array is.
NathanOliver
Veteran Poster
1,084 posts since Apr 2009
Reputation Points: 215
Solved Threads: 189
You log in and click your name on the top left hand corner then click statistics >> Find all threads started by name. Then just select the thread that you want to go to. To mark as solved scroll to the bottom where it says reply to thread in a yellow box and just to the right of that is blue text that says mark as solved.
sfuo
Practically a Master Poster
656 posts since Jul 2009
Reputation Points: 164
Solved Threads: 99
I'm not sure because when I was doing some testing I made a char array size 2 and the size of it said it was 2 bytes in size but there were 5 characters in the array.
sfuo
Practically a Master Poster
656 posts since Jul 2009
Reputation Points: 164
Solved Threads: 99
Thank you; ^ and ^^ for your prompt reply :)
I have another problem similar problem; i.e.
now ONCE i have declared a char array of a particular size; if I add more values into other indexes of it; it stores them; its like the char array is EXPANDING automatically; while in int array; it gives an error !! Why does this happen ?
Bottom line, array does not resize itself. Your problem has to
do with memory. Your code has a bug; You declared char arraY[1],
but in your for loop you are looping it from 0 to 2, which has 3 index.
Again, arrays does not resize its self, nor does it check for bound
errors. Don't worry about whats happening in the memory right
now. Just remember that when you have a code similar to this :
data_type dataVariableArray[ someConstantNumber ] ;
That array has elements from 0 to someConstantNumber - 1,
anything else then its invalid.
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
the reason that you can go beyond the array size is that in c++ it is leagal to increment the pointer past the size of the array. its a through back to c. you cant start before the array like index = -1 but if the size of the array is 2 it is legal to go the index = 2.
char temp[1];
temp[-1] // cannot be done
temp[1] // okay even though the data is only in temp[0]
NathanOliver
Veteran Poster
1,084 posts since Apr 2009
Reputation Points: 215
Solved Threads: 189