小编Nin*_*Yo.的帖子

谁能向我解释为什么这个atoi命令有效以及如何工作

我用atoi命令编写了一个非常基本的c代码,然后执行它.

void
main
(void)
{
    int length;

    length = atoi("Content: 111");
    printf("atoi(\"Content: 111\") =  %d\n",length);

    length = atoi("Content:    111" + 10);
    printf("atoi(\"Content:    111\" + 10) = %d\n",length);

    length = atoi("Content: 1" + 6);
    printf("atoi(\"Content: 1\" + 6) = %d\n",length);

    length = atoi("Content: 111" + 12);
    printf("atoi(\"Content: 111\" + 12) = %d\n",length);

    length = atoi("Content-aaaaaa:            111" + 20);
    printf("atoi(\"Content-aaaaaa:            111\" + 20) = %d\n",length);

    printf("\"aaa\"+7 = %s","aaa"+7);
}
Run Code Online (Sandbox Code Playgroud)

输出如下:

atoi("Content: 111") =  0
atoi("Content:    111" + 10) = 111
atoi("Content: 1" …
Run Code Online (Sandbox Code Playgroud)

c atoi string-literals pointer-arithmetic

0
推荐指数
1
解决办法
489
查看次数

标签 统计

atoi ×1

c ×1

pointer-arithmetic ×1

string-literals ×1