我想编写一个返回用户名和密码的访问函数.这是我想出的:
#include <stdio.h>
char *
getMySQLUsername()
{
return "myUsername";
}
char *
getMySQLPassword()
{
return "myPassword";
}
int main()
{
printf("%s\n", getMySQLPassword());
}
Run Code Online (Sandbox Code Playgroud)
它似乎工作,但这个代码是否正确?
您应该返回,const char *因为您无法更改文字字符串.你也没有返回任何东西main,它只在C99和C++中的C中有效.