char * return (null) from a function in C [duplicate]
问题 This question already has answers here : Returning an array using C (8 answers) Closed last month . I was trying to append two const char* from a function but it returns (null) . What should I do now? I'm working in VS Code on Ubuntu 20.04 using GCC Compiler v9.3.0. Code #include <string.h> #include <stdio.h> char *JoinChars(const char *a, const char *b) { char buffer[strlen(a) + strlen(b) + 1]; strcpy(buffer, a); strcat(buffer, b); return buffer; } int main() { const char *b1 = "Hello\t";