C++点滴

(×)程序运行时间统计代码

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?

source

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声明在什么情况下用?


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值