Novice C language learning journey(5)

梦幻光晕蓝色背景矢量图.png
This code has a error when run it,the compiler shows "[Warning] return makes integer from pointer without a cast".
Why it shows this error?
The "world" function is char type.So the return type must be char type.But the formal parameter of "world" function is "char*" type.
So the type is not match.The code as follows:

#include"stdio.h"
char world(char name[5]){
strcpy(name,"abs");
printf("%s",name);
return(name);
}
int main(void){
char a[12];
world(a);
return 0;
}
捕获.PNG
So how to modify?
the solution as follows:

#include"stdio.h"
char* world(char name[5]){
strcpy(name,"abs");
printf("%s",name);
return(name);
}
int main(void){
char a[12];
world(a);
return 0;
}
捕获45.PNG

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center