If you create a local variable inside a function, when that function ends the memory that variable is using will be reused.
So in the function print(), the array char out[30]; gets overwritten after the function ends. So you have a pointer to some memory that's being overwritten.
Are you using char arrays instead of strings for a good reason? C++ does have string types, which come with helpful functions for turning numbers to strings and string to numbers.