开发者

C: Simple pointer question

开发者 https://www.devze.com 2023-03-20 21:29 出处:网络
I want to program an access function that returns username and password. Here\'s what I came up with:

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

精彩评论

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