从零开始的数字有什么特别之处?

编程入门 行业动态 更新时间:2024-10-24 18:28:54
本文介绍了从零开始的数字有什么特别之处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是一个愚蠢的问题,但对我来说很有趣)

This is kinda stupid question, but it's interesting for me )

这是我在Visual Studio 2013中得到的东西

This is what i get with visual studio 2013

int i = 07; // i == 7 int i = 16; // i == 16 int i = 00016; // i == 14, why? int i = 05016; // i == 2574, wow ) int i = 08; // compile error, compiler expects octal number...

如果数字以零开头且包含8,这是编译错误。这正常吗?以及如果00016 == 14,编译器到底从零开始做什么?

If number starts with zero and contains 8, it's compile error. Is this normal? And what exactly compiler does with starting zeros if 00016 == 14?

感谢所有人))

推荐答案

是的,这是预期的。

[C ++ 11:2.14 .2 / 1]: 整数文字是没有句号或指数部分的数字序列。整数文字可以具有指定其基数的前缀和指定其类型的后缀。数字序列的词法上的第一个数字是最高有效的。 十进制整数文字(以10为底)以非0的数字开头,并由一系列十进制数字组成。 八进制整数文字(以8为底)以数字0开头,由八进制数字序列组成。 22 一个十六进制整数文字(基数为16)以0x或0X开头,由一系列十六进制数字组成,其中包括十进制数字以及字母a至f和a至f,十进制值为10至15。 [示例:可以将数字十二写为12、014或0XC。 -结束示例]

[C++11: 2.14.2/1]: An integer literal is a sequence of digits that has no period or exponent part. An integer literal may have a prefix that specifies its base and a suffix that specifies its type. The lexically first digit of the sequence of digits is the most significant. A decimal integer literal (base ten) begins with a digit other than 0 and consists of a sequence of decimal digits. An octal integer literal (base eight) begins with the digit 0 and consists of a sequence of octal digits.22 A hexadecimal integer literal (base sixteen) begins with 0x or 0X and consists of a sequence of hexadecimal digits, which include the decimal digits and the letters a through f and A through F with decimal values ten through fifteen. [ Example: the number twelve can be written 12, 014, or 0XC. —end example ]

22 数字8和9不是八进制数字。

更多推荐

从零开始的数字有什么特别之处?

本文发布于:2023-07-27 03:02:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219961.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么   之处   从零开始   数字

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!