C 常量的类型
2013-06-23 01:13
288 查看
http://bbs.csdn.net/topics/380028485
整型常量的类型是下列相应表中第一个能表示其值的类型:
int --> long int --> long long int
无后缀的十进制整数常量:int,long int,long long int
以字母u或U为后缀的十进制整型常量:unsigned int,unsigned long int,unsigned long long int
以字母l或L为后缀的十进制整型常量:long int,long long int
同时以字母u或U和字母l或L为后缀的十进制整型常量:unsigned long int,unsigned long long int
以字母ll或LL为后缀的十进制整型常量:long long int
同时以字母u或U和字母ll或LL为后缀的十进制整型常量:unsigned long long int
无后缀的八进制或十六进制常量:int,unsigned int,long int,unsigned long int,long long int,unsigned long long int
以字母u或U为后缀的八进制或十六进制常量:unsigned int,unsigned long int,unsigned long long int
以字母l或L为后缀的八进制或十六进制常量:long int,unsigned long int,long long int,unsigned long long int
同时以字母u或U和字母l或L为后缀的八进制或十六进制常量:unsigned long int,unsigned long long int
以字母ll或LL为后缀的八进制或十六进制常量:long long int,unsigned long long int
同时以字母u或U和字母ll或LL为后缀的八进制或十六进制常量:unsigned long long int
http://www.rapidtables.com/prog/cref/const.htm
Numbers characters and string constants.
See enum end const in data types page.
http://stackoverflow.com/questions/7036056/what-do-0ll-or-0x0ul-mean
These are constants in C and C++.
The suffix
In general, each
each
This also applies to floating point numbers:
and strings and characters, but they are prefixes:
In C and C++ the integer constants are evaluated using their original type,
which can cause bugs due to integer overflow:
In Google Go, all integers are evaluated as big integers (no truncation happens),
and there is no "usual arithmetic promotion"
so the suffixes are not necessary.
整型常量的类型是下列相应表中第一个能表示其值的类型:
int --> long int --> long long int
无后缀的十进制整数常量:int,long int,long long int
以字母u或U为后缀的十进制整型常量:unsigned int,unsigned long int,unsigned long long int
以字母l或L为后缀的十进制整型常量:long int,long long int
同时以字母u或U和字母l或L为后缀的十进制整型常量:unsigned long int,unsigned long long int
以字母ll或LL为后缀的十进制整型常量:long long int
同时以字母u或U和字母ll或LL为后缀的十进制整型常量:unsigned long long int
无后缀的八进制或十六进制常量:int,unsigned int,long int,unsigned long int,long long int,unsigned long long int
以字母u或U为后缀的八进制或十六进制常量:unsigned int,unsigned long int,unsigned long long int
以字母l或L为后缀的八进制或十六进制常量:long int,unsigned long int,long long int,unsigned long long int
同时以字母u或U和字母l或L为后缀的八进制或十六进制常量:unsigned long int,unsigned long long int
以字母ll或LL为后缀的八进制或十六进制常量:long long int,unsigned long long int
同时以字母u或U和字母ll或LL为后缀的八进制或十六进制常量:unsigned long long int
http://www.rapidtables.com/prog/cref/const.htm
Numbers characters and string constants.
See enum end const in data types page.
Data Type Constants
Syntax | Description | Example |
---|---|---|
0xhexnum 0Xhexnum | hexadecimal number | int x=0x7FFF0000; |
0 octnum | octal number | int x=07654321; |
num u num U | unsigned integer number constant | unsigned int x=1000U; |
num l num L | long integer number constant | long x=-99999L; |
num ul num UL | unsigned long integer number constant | unsigned long x=99999L; |
num ll num LL | long long integer number constant | long long x=-888888LL; |
num ull num ULL | unsigned long long integer number constant | unsigned long long x=100ULL; |
num f num F | float number constant | float x=0.005F; |
num l num L | long double number constant | long double x=0.005L; |
num e±exp num E±exp | floating point exponent number constant | double x=5.2E-3; |
'char' | character constant | char c='A'; |
"string" | string constant | char name[6]="Hello"; |
These are constants in C and C++.
The suffix
LLmeans the constant is of type
long long, and
ULmeans
unsigned long.
In general, each
Lor
lrepresents a
longand
each
Uor
urepresents an
unsigned. So, e.g.
1uLL // means the constant 1 with type unsigned long long.
This also applies to floating point numbers:
1.0f // of type 'float' 1.0 // of type 'double' 1.0L // of type 'long double'
and strings and characters, but they are prefixes:
'A' // of type 'char' L'A' // of type 'wchar_t' u'A' // of type 'char16_t' (C++0x only) U'A' // of type 'char32_t' (C++0x only)
In C and C++ the integer constants are evaluated using their original type,
which can cause bugs due to integer overflow:
long long nanosec_wrong = 1000000000 * 600; // ^ you'll get '-1295421440' since the constants are of type 'int' // which is usually only 32-bit long, not big enough to hold the result. long long nanosec_correct = 1000000000LL * 600 // ^ you'll correctly get '600000000000' with this int secs = 600; long long nanosec_2 = 1000000000LL * secs; // ^ use the '1000000000LL' to ensure the multiplication is done as 'long long's.
In Google Go, all integers are evaluated as big integers (no truncation happens),
var nanosec_correct int64 = 1000000000 * 600
and there is no "usual arithmetic promotion"
var b int32 = 600 var a int64 = 1000000000 * b // ^ cannot use 1000000000 * b (type int32) as type int64 in assignment
so the suffixes are not necessary.
相关文章推荐
- 第二章 java基础(常量类型)
- C++ 入门教程(七) auto、decltype、常量、类型后缀 和 const
- Java中的常量、变量、以及数据类型的简单知识分享。
- JAVA基础复习二-常量、进制和数据类型
- 第二节:常量,进制与基本数据类型(讲师笔记篇)
- C++确定常量的数据类型
- 第2课 Go类型、变量、常量、运算符
- C++程序员学Java系列之五:常量,变量,基本数据类型及转换
- 黑马程序员_03_标示符_常量_进制_变量_类型转换
- 2014.01.04php之变量类型以及常量使用
- C++如何确定常量的类型
- Effective Objective-C 2.0 — 第四条:多用类型常量,少用#define预处理指令
- 不可或缺 Windows Native (2) - C 语言: 常量,变量,基本数据类型
- JavaSE-day1 关键字 数据类型 常量
- 黑马程序员——C语言基础(二)数据类型、常量以及变量
- 2. 包类结构、数据类型、变量与常量、运算符、注释与规范
- Sql2012如何将远程服务器数据库及表、表结构、表数据导入本地数据库 自定义日志记录功能,按日记录,很方便 C#常量和字段以及各种方法的语法总结 类型,对象,线程栈,托管堆在运行时的关系,以及clr如何调用静态方法,实例方法,和虚方法 asp.net webapi 自定义身份验证
- FLWSCRIPT语法-关键字数据类型变量常量
- PHP学习笔记-1(变量、常量、类型、作用域、数组、字符串、大小写)
- 参数中有const时进行数据类型的转换问题-固定变量转常量