开发者

C: Simple pointer question

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++.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜