Why is s larger than [5]? How do I make s[5]?
Code:#include <iostream.h> void main() { char * s; s = new char[5]; s[0] = 'h'; s[1] = 'e'; s[2] = 'l'; s[3] = 'l'; s[4] = 'o'; cout << s << "<end of string>" << endl; delete s; }
output:
I could add the code...Code:hello²²²²<end of string> Press any key to continue
but I get access violation. But it clears the garbage on the end before it crashes.Code:s[5] = ' '; s[6] = ' '; s[7] = ' '; s[8] = ' ';




Reply With Quote