Why return malloc'd char array not work, but local char array does?

This is a discussion on Why return malloc'd char array not work, but local char array does? within the C++ Programming forums, part of the General Programming Boards category; Inside a function, I create a char array which I pass to a library function that fills it with a ...

Why return malloc'd char array not work, but local char array does?

Inside a function, I create a char array which I pass to a library function that fills it with a value. I then pass this back to the caller. When I do it by creating an array with malloc (and then freeing it outside the function), it only fills the array with the first 3 characters. When i create it as a local array, it works (and simply warns me I'm passing a local array back out).