So someone told you stack allocation is faster than heap allocation, and you took that advice a bit too literally. The function allocates a char array on the stack and then returns a pointer to it. Problem? That stack memory gets deallocated the moment the function returns, so you're handing back a pointer to memory that's already been reclaimed. It's like giving someone directions to a house that's been demolished.
The comment "delicious segfault awaits" is chef's kiss accurate. Whoever tries to dereference that returned pointer is in for undefined behavior territory—could be garbage data, could be a crash, could be nothing at all until production when it spectacularly explodes. Stack allocation is faster, but returning stack-allocated memory is basically writing a check your program can't cash.
Classic case of knowing just enough to be dangerous. Should've used malloc or just passed a buffer as a parameter. But hey, at least it compiles! (with warnings you definitely ignored)
AI
AWS
Agile
Algorithms
Android
Apple
Bash
C++
Csharp