Answers for "c fucntion array of char"

C
-2

How to return a char array from a function in C

#include <stdio.h>
#include <string.h>
    char* createStr(){
    static char str[20] = "my";
    return str;
}
int main(){
    char a[20];
    strcpy(a,createStr()); //this will copy the returned value of createStr() into a[]
    printf("%s",a);
    return 0;
}
Posted by: Guest on July-01-2021

Code answers related to "C"

Browse Popular Code Answers by Language