char* pStr = new String("Hello");
char* s = "Hello";
Is the first one correct? Are there any difference between these two? My guess is that the first one is allocated on the heap,and the other one an the stack.Am i correct or are there any other differences?
The first one is just incorrect and won’t compile because there is no such thing as
Stringin either C or C++. The second one will compile, and is fine in C(afaik). In C++, however, the conversion from a string literal tochar*is deprecated. You can unintentionally write laters[0] = 'X';which is undefined behavior.The correct way of doing it is using const (in C++)
or, better, use string