C ++中以十六进制或八进制表示的整数的默认类型是什么? [英] What is the default type of integral literals represented in hex or octal in C++?

查看:126
本文介绍了C ++中以十六进制或八进制表示的整数的默认类型是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,整数的类型定义如下:

What is by default type of integral literal defined below:

0X123 /* hex , int ? unsigned int? long? unsigned long? */
0XFFFFFFFE /* hex , value is (2^32-2)=4294967294 .*/ 
0123 /*octal */ /* value = 83*/
042747672777 /* octal , greater than 2^32*/ /* value=4691293695 */

我在某些教程中阅读过,或者本书(我不记得源代码)默认情况下它们是带符号的int类型。

I read in some tutorial or book (I don't remeber source) that they are by default of signed int type. Is that correct?

推荐答案

整数文字的类型较少定义为是十六进制文字,十进制文字,

The type of the integral literal is defined less by whether it is a hexadecimal literal, a decimal literal, or an octal literal and more by the value of the literal.

表6 —整数常量的类型,在第2.14.2节中C ++ 11 Standard列出了将用于捕获整数文字的类型的顺序。

Table 6 — Types of integer constants, in Section 2.14.2 of the C++11 Standard lists the order of types that will be used to capture an integral literal.

十进制文字与十六进制和八进制文字之间的主要区别在于顺序十进制文字类型的类型是 int long long long 十六进制和八进制文字的类型顺序为 int unsigned int long unsigned long long long unsigned long long

The main difference between decimal literals and hexadecimal and octal literals is that the order of types of decimal literals is int, long, long long while the order of types of hexadecimal and octal literals is int, unsigned int, long, unsigned long, long long, and unsigned long long.

这篇关于C ++中以十六进制或八进制表示的整数的默认类型是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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