C++学习之数据处理

1、C++变量命名的规范:

在名称中只能使用字母字符、数字和下划线(_)。
名称的第一个字符不能是数字。
区分大写字符和小写字符。
不能将C++关键字用作名称。
以两个下划线或下划线和大写字母打头的名称被保留给实现(编译器机器使用的资源)使用,以一个下划线开头的名称被保留给实现,用作全局标识符。
C++对于名称的长度没有限制,名称中所有的字符都有意义。
以下名称都是不可用的:_Mystars3、4ever、double、__floors、honky-tonk
常用的变量命名前缀规范:n(整形常量)、str或sz(表示以空字符结束的字符串)、b(表示布尔值)、p(表示指针)和c(表示单个字符)

2、C++变量的长度
a. short、int和long
short至少16位、int至少与short一样长、long至少32位,且至少与int一样长。
通过以下代码我们可以查看机器上的以上三种类型的长度:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//Limits.cpp -- some integer limits
   
#include <iostream>
#include <climits>
   
using namespace std;
   
int main(int argc, char** argv[])
{
    int nInt = INT_MAX; //initialize nInt to max int value symbols defined in limits.h file
    short sShort = SHRT_MAX;
    long lLong = LONG_MAX;
   
    //sizeof operator yields size of type or of variable
    cout << "int is " << sizeof(int) << " bytes." << endl;
    cout << "short is " << sizeof(short) << " bytes." << endl;
    cout << "long is " << sizeof(long) << " bytes." << endl;
    //sizeof对类型名使用时应将其放在括号中,而对变量使用时括号是可选的
    cout << "another int is " << sizeof nInt << " bytes." << endl; 
   
    cout << "Maximum values: " << endl;
    cout << "int: " << nInt << endl;
    cout << "short: " << sShort << endl;
    cout << "long: " << lLong << endl;
   
    cout << "Minimum int value = " << INT_MIN << endl;
    cout << "Bits per byte = " << CHAR_BIT << endl;
   
    system("pause");
    return 0;
}
b.limits中定义的符号常量
 




posted @ 2012-09-16 22:38  glc400  阅读(254)  评论(0编辑  收藏  举报