(×)程序运行时间统计代码
http://stackoverflow.com/questions/876901/calculating-execution-time-in-c
http://stackoverflow.com/questions/2808398/easily-measure-elapsed-time
( × ) 变量类型范围和数的二进制表示
int var_int_min = 0xFFFFFFFF;
int var_int_max = 0x7FFFFFFF;
cout << "var_int_min: " << var_int_min << endl; //输出-1,why?
cout << "var_int_max: " << var_int_max << endl;
// cout << "the size of is: " << sizeof() << endl;
cout << "the size of bool is: " << sizeof(bool) << endl;
cout << "the size of char is: " << sizeof(char) << endl;
cout << "the size of wchar_t is: " << sizeof(wchar_t) << endl;
cout << "the size of char16_t is: " << sizeof(char16_t) << endl;
cout << "the size of char32_t is: " << sizeof(char32_t) << endl;
cout << "the size of short is: " << sizeof(short) << endl;
cout << "the size of int is: " << sizeof(int) << endl;
cout << "the size of long is: " << sizeof(long) << endl;
cout << "the size of long long is: " << sizeof(long long) << endl;
cout << "the size of float is: " << sizeof(float) << endl;
cout << "the size of double is: " << sizeof(double) << endl;
cout << "the size of long double is: " << sizeof(long double) << endl;
输出
var_int_min: -1
var_int_max: 2147483647
the size of bool is: 1
the size of char is: 1
the size of wchar_t is: 2
the size of char16_t is: 2
the size of char32_t is: 4
the size of short is: 2
the size of int is: 4
the size of long is: 4
the size of long long is: 8
the size of float is: 4
the size of double is: 8
the size of long double is: 8
How to get the type of a variable or a literal?
use typeid operator
#include <typeinfo>
...
cout << typeid(variable).name() << endl;
extern和include的用法区别???
extern_test.h
int ext = 0;
source.cpp
#include "extern_test.h"
#include <iostream>
using namespace std;
int main() {
cout << ext << endl;
return 0;
}
两个文件,source只要include.h文件,就能正常使用ext. extern声明在什么情况下用?