为什么价值会发生变化 [英] Why the value changes

查看:92
本文介绍了为什么价值会发生变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<stdio.h>
#include<conio.h>
void main()
{
int a=16,b=012,c=054;
printf("a=%d b=%d c=%d",a,b,c);

}





我的尝试:



为什么输出改变了什么是转换......



What I have tried:

why the output changes what is the conversion...

推荐答案

当你在C中用0加前缀时,它假设你输入的数字不是十进制的长数(基数10,我们通常在现实世界中使用的那个)而是八进制数(基数8,它运行0,1,... 7,10,11,... 17,20,21,...)

所以这个:

When you prefix a number with 0 in C it assumes that the number you are inputting is no long in decimal (base 10, the one we normally use in the real world) but instead in octal (base 8, it runs 0, 1, ... 7, 10, 11, ... 17, 20, 21, ...)
So this:
int a=16,b=012,c=054;

为它们创建三个变量和分配值:

Creates three variables and assignes values to them:

a    16   deciml, value 16
b   012   octal,  value 10 in decimal
c   054   octal,  value 44 in decimal



你也可以用0x或0X前缀数字输入十六进制(或只是十六进制)数字

- 这些日子比八进制更常见。



见这里: Octal - Wikipedia [ ^ ]

这里:十六进制 - 维基百科 [ ^ ]


这篇关于为什么价值会发生变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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