在C中存储以零开头的值变异,为什么? [英] In C storing values that start with zero get mutated, why?

查看:127
本文介绍了在C中存储以零开头的值变异,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

int main(){

    int x = 01234567;

    printf("\n%d\n",x);

    return 0;

}

以下代码生成:342391

The following code produces: 342391

如果我在开头没有包含0,那么值x将是1234567,为什么C以这种方式存储值并且有没有办法让它不这样做?

If I didn't include the 0 at the beginning, the value x would be 1234567, why does C store the value this way and is there any way to get it from not doing this?

推荐答案

因为以0开头的数字表示为八进制数。你无法真正修改这种行为,只是不要在开头包含零。

Because numbers starting with 0 are represented as octal numbers. You cannot really modify this behavior, simply do not include the zero at the beginning.

这篇关于在C中存储以零开头的值变异,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆