I think there are about three ways you can initialize a character string. I have been having some trouble understanding why I cannot write to a string allocated using the third initialization below.
Code:char* str = new Char[13]; str = "Hello World!";Code:char str[] = "Hello World!";Now let's suppose that I want to modify one of the strings by doingCode:char* str = "Hello World!";
For the first two strings, this works perfectly fine, but for the third one, I get memory access violation error. Is this happening because in the third case, the characters are written to the section of memory between stack and heap block where no user is supposed access? I'd greatly apprecaite for the help. Thanks.Code:str[0] = 'Y'



LinkBack URL
About LinkBacks


