Chinaunix首页 | 论坛 | 博客
  • 博客访问: 87270
  • 博文数量: 60
  • 博客积分: 4002
  • 博客等级: 中校
  • 技术积分: 645
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-17 18:11
文章分类

全部博文(60)

文章存档

2011年(60)

我的朋友

分类: C/C++

2011-01-05 14:48:20

    Fundamental Types:bool, char, int, double,enum,void, int *, char[], double&, Datastructures and class.
   
    The Boolean, character, and integer types are collectively called integral types. The integral and floating point types are collectively called arithmetic types. Enumerations and classes are called user defined types, In contrast, other types are called built-in types.

    A Boolean, bool , can have one of the two values true or false.

    A variable of type char can hold a character of the implementation’s character set.
C++ provides two types for which the answer is definite; signed char , which can hold at least the values -127 to 127 ,and unsigned char , which can hold at least the values 0 to 255 .
A type wchar_t is provided to hold characters of a larger character set such as Unicode.

    each integer type comes in three forms: ‘plain’ int , signed int , and unsigned int . In
addition, integers come in three sizes: short int , ‘plain’ int , and long int . A long int can be referred to as plain long . Similarly, short is a synonym for short int , unsigned for unsigned int , and signed for signed int .
    Unlike plain chars, plain int s are always signed. The signed int types are simply more explicit synonyms for their plain int counterparts.
    Integer literals come in four guises: decimal, octal, hexadecimal, and character literals.

    Like integers, floating point types come in three sizes: float (singleprecision), double (doubleprecision), and long double (extendedprecision).
    1 == sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long)
    1 <= sizeof(bool) <= sizeof(long)
     sizeof(char) <= sizeof(wchar_t) <= sizeof(long)
    sizeof(float) <= sizeof(double) <= sizeof(long double)
    sizeof(N) == sizeof(signed N) == sizeof(unsigned N)
    In addition, it is guaranteed that a char has at least 8 bits, a short at least 16 bits, and a long at least 32 bits.

    The type void is syntactically a fundamental type. It can, however, be used only as part of a more complicated type; there are no objects of type void . It is used either to specify that a function does not return a value or as the base type for pointers to objects of unknown type. void is used as a ‘pseudo return type’ to indicate that a function doesn’t return a value.

    An enumeration is a type that can hold a set of values specified by the user. Once defined, an enumeration is used very much like an integer type.

    Before a name (identifier) can be used in a C++ program, it must be declared.

    A name (identifier) consists of a sequence of letters and digits. The first character must be a letter. The underscore character _ is considered a letter.

    Advice:
[1] Keep scopes small;
[2] Don’t use the same name in both a scope and an enclosing scope;
[3] Declare one name (only) per declaration;
[4] Keep common and local names short, and keep uncommon and nonlocal names longer;
[5] Avoid similarlooking names;
[6] Maintain a consistent naming style;
[7] Choose names carefully to reflect meaning rather than implementation;
[8] Use a typedef to define a meaningful name for a builtin type in cases in which the builtin
type used to represent a value might change;
[9] Use typedefs to define synonyms for types; use enumerations and classes to define new types;
[10] Remember that every declaration must specify a type (there is no ‘implicit int ’);
[11] Avoid unnecessary assumptions about the numeric value of characters;
[12] Avoid unnecessary assumptions about the size of integers;
[13] Avoid unnecessary assumptions about the range of floatingpoint types;
[14] Prefer a plain int over a short int or a long int ;
[15] Prefer a double over a float or a long double ;
[16] Prefer plain char over signed char and unsigned char ;
[17] Avoid making unnecessary assumptions about the sizes of objects;
[18] Avoid unsigned arithmetic;
[19] View signed to unsigned and unsigned to signed conversions with suspicion;
[20] View floatingpoint to integer conversions with suspicion;
[21] View conversions to a smaller type, such as int to char , with suspicion;
   
阅读(579) | 评论(0) | 转发(0) |
0

上一篇:libsys

下一篇:popen & fgets & fputs

给主人留下些什么吧!~~