C++ Primitive Data Types_C/C++_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > C/C++ > C++ Primitive Data Types

C++ Primitive Data Types

 2012/6/11 0:14:22  Jia_er  程序员俱乐部  我要评论(0)
  • 摘要:1.NumericDataTypes(9kinds)NameSynonymyStrorageSizeshortshortint16-bitsignedunsignedshortunsignedshortint16-bitunsignedint---32-bitsignedunsignedintunsigned32-bitunsignedlonglongint32-bitsignedunsignedlongunsignedlongint32-bitunsignedfloat---32
  • 标签:c++

1. Numeric Data Types( 9 kinds )

? ? Name Synonymy Strorage Size

? ? short ? short int? 16-bit signed

? ? unsigned short? unsigned short int? 16-bit unsigned

? ? int --- 32-bit signed

? ? unsigned int? unsigned 32-bit unsigned

? ? long long int? 32-bit signed

? ? unsigned long? unsigned long int? 32-bit unsigned

? ? float --- 32-bit IEEE 754

? ? double --- 64-bit IEEE 754

? ? long double? --- 80-bit

?

2. Numeric Type Convertions

  • if one of the operands is long double, the other is converted into long double;
  • Otherwise, if one of the operands is double, the other is converted into double;
  • Otherwise, if one of the operands is float, the other is converted into float;
  • Otherwise, if one of the operands is unsigned long, the other is converted into unsigned long;
  • Otherwise, if one of the operands is long, the other is converted into long;
  • Otherwise, if one of the operands is unsigned int, the other is converted into unsigned int;
  • Otherwise, both operands are converted into int.
? ? ? Casting Operator : static_cast<type>(value)
3. ?Character Data Type ? ? ?Name StorageSize ? ? ?char? ? ? ? ? ? ? ? ? ? ? ? ?1 character?
4. Casting between char and Numeric Types
  • char can be cast into any numberic type, and vice versa.
  • When an integer is cast into a char, only its lower 8 bits of data are used.
  • When a floating-point value is cast into a char, the floating-point vlaue is first cast into an int, which is then cast into a char.
5. bool Data Type ? ? Name StorageSize ? ? bool ? ? ? ? ? ? ? ? ? ? ? ?1 character? ? ? In C++, any nonzero value evaluates true and zero value evaluates false. ?

6. widening a type v.s. narrowing a type?

  • widening a type : casting a variable of a type with a small range to a variable of a type with a larger range.
  • narrowing a type : casting a variable of a type with a large range to a variable of a type with a smaller range.?
  • Narrowing a type may lose precision.
7. switch ( switch-expression ) ? ? In C++, a char or bool value is treated as an integral. So, this type of value used in a switch statement as a switch expression or case value.

?

发表评论
用户名: 匿名