char arrays...


I'm just wondering, at function level if I do the below, do I need to destroy the char array sString at the end?

void SomeVoid( )
	char sString[500] = "";
	Q_snprintf( sString, sizeof( sString ), "%s", "Some String" );

Open in new window

LVL 10
Who is Participating?
>> do I need to destroy the char array sString at the end?

When the function ends, the (local) char array is also removed. You don't have to remove it explicitly.
c0ldfyr3Author Commented:
Thanks that's what I thought.
To add to above:

You only have to destroy (delete) if you allocated with new operator.

You should try to have new/delete always with in the same scope.

void someFunc()
    char* psz = new char[1000];
    // do somewhat with psz

    delete []psz;

If you do the new in the constructor or member function of a class and the pointer should be valid beyond the current scope, store it in a pointer member of the class and delete it in the destructor.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.