小编Got*_*est的帖子

为什么程序只在main中定义输出(如何更改)?

我试着跑这个

int array( void )
{
    char text[12] = {  112, 114, 111, 103, 112, 0 };
    int i;
    for(i = 0; text[i]; i = i +1)
        printf("%c", text[i]);
    printf("\n");
    return 0;
}

int main( void )
{
    int array(void);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

程序运行,但我没有结果.现在当我使用main函数定义程序时:

int main( void )
{
    char text[12] = {  112, 114, 111, 112, 0 };
    int i;
    for(i = 0; text[i]; i = i +1)
        printf("%c", text[i]);
    printf("\n");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我得到了结果progr(按照需要).我已经搜索过,但我发现的唯一相关问题是关于使用main函数名称和输出错误.也许我正在寻找错误的方式,但如果有人能够回答这个问题,我会很高兴.

c program-entry-point function output

5
推荐指数
0
解决办法
126
查看次数

为什么使用long作为数据类型使'隐式转换失去整数精度'消失?

我知道这个标题有很多问题,但我不是在寻找解决方案.我想知道为什么会这样.我将此作为解决方案

int points[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

int *pos = points + 5;

int index = pos - points;
Run Code Online (Sandbox Code Playgroud)

但当我使用该代码时,我得到警告隐式转换失去整数精度:'long'到'int'.现在当我使用long作为索引的数据类型

int points[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

int *pos = points + 5;

long index = pos - points;
Run Code Online (Sandbox Code Playgroud)

它没有发出警告.我试着用很长时间,因为我记得一些关于指针和长期的东西.但是指针没有数据类型(如果我错了请纠正我).点和*pos都用int初始化.那么为什么long fit和int不呢?

为什么他们在解决方案中使用int?解决方案是错误的还是关于xCode(我正在使用)?

谢谢你的回答

c arrays pointers

4
推荐指数
2
解决办法
109
查看次数

标签 统计

c ×2

arrays ×1

function ×1

output ×1

pointers ×1

program-entry-point ×1