I want to program an access function that returns username and password. Here's what I came up with:
#include <stdio.h>
char *
getMySQLUsername()
{
return "myUsername";
}
char *
getMySQLPassword()
{
return "myPassword";
}
int m开发者_StackOverflow中文版ain()
{
printf("%s\n", getMySQLPassword());
}
It seems to work, but is this code correct?
You should return const char *
because you cannot change a literal string. You're also not returning anything from main
, which is only valid in C as of C99 and in C++.
精彩评论