What happens if I increment an array variable?

you cannot change the address of an array. It will give a compile time error. have a look: http://codepad.org/skBHMxU0

EDIT:

the comments made me realize your true intent:
something like:

char *ptr = "one two three";
ptr++;

There is no problem with it. the string “one two three” is a constant, and you can freely modify ptr, but note you might have troubles later finding the start of this string again… [but memory leak will not occur]

As a thumb rule, you are responsible for the memory you specifically allocated using malloc/new, and the compiler is responsible for the rest.

Leave a Comment