[Solved] Why does the second call to name() print “Alex . n”?


You took the variable n, declared statically inside name(), which pointed to a C-string " Justin ", then made it point to a C-string " Alex ".

So, naturally, when you inspect it later, it still points to a C-string " Alex ".

Remember, you declared it statically. That means every invocation of name() shares the same variable.

If function-static variables were to re-take their initialiser’s value every time you entered the function, there would be absolutely no point in making them static!

4

solved Why does the second call to name() print “Alex . n”?