array return type

后端 未结 5 780
有刺的猬
有刺的猬 2021-01-29 15:25
#include
#include
#define MAX 30

void push(char );


char stack[MAX];
int tos=0;

int main(){
    char str[]=\"Arijit Saha\";
    char *f         


        
5条回答
  •  悲哀的现实
    2021-01-29 16:14

    A variable which has automatic storage duration doesn't exist anymore in the calling function. Accessing to it leads to an undefined behavior (anything can happen). Here you are returning reverse from rev, which is a local variable.

    Rather allocate the memory dynamically:

    int *reverse = malloc(strlen(s)); /* + 1 for '\0' character ? */
    

提交回复
热议问题