G
gallows
In this code:
void f()
{
char* s1 = new char;
s1 = "fred";
char* s2 = new char[4];
s2 = "fred";
}
What is the difference between s1 and s2?
When I should use new[]?
Why if I append "delete[] s1" I get: "*** glibc detected *** ./foo:
free(): invalid pointer: 0x0804874c ***" ?
I know that seems stupid, but it's not clear for me.
Thanks.
s.
void f()
{
char* s1 = new char;
s1 = "fred";
char* s2 = new char[4];
s2 = "fred";
}
What is the difference between s1 and s2?
When I should use new[]?
Why if I append "delete[] s1" I get: "*** glibc detected *** ./foo:
free(): invalid pointer: 0x0804874c ***" ?
I know that seems stupid, but it's not clear for me.
Thanks.
s.