基础类型

c++标准保证:1 == sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(long long)


void类型:值为空值的类型。也不存在含有void的数组以及到void的引用;但是指向void的指针和返回void类型的函数是允许存在的。

如以下代码:

#include<iostream>
using namespace std;
void MyPrintf(void);
int main(int argc, const char* argv[])
{
	void array[10];		//错误,不允许使用void的数组
	void* ptr;			//正确
	MyPrintf();			//正确
	return 0;
}
void MyPrintf(void)
{
	cout << "hello world" << endl;
}

bool类型:足以存放两个值truefalse之一的类型,sizeofbool)的值由实现定义,而且不一定是1

如以下代码:

#include<iostream>
using namespace std;
int main(int argc, const char* argv[])
{
	bool number;
	number = true;
	cout << number << endl;		//true为真,此时number的值也应为1
	number = false;
	cout << number << endl;		//false为假,此时number的值也应为0

	cout << "sizeof(bool):" << sizeof(bool) << endl;
	return 0;
}

数据模型:我们重点关注64位系统下的数据模型。intlong32位,指针是64位。

如以下代码:

#include<iostream>
using namespace std;
int main(int argc, const char* argv[])
{
	int* ptr;
	cout << "sizeof(int):"	<< sizeof(int)	<< endl;	//4字节 
	cout << "sizeof(long):" << sizeof(long) << endl;	//4字节
	cout << "sizeof(ptr):"	<< sizeof(ptr)	<< endl;	//8字节
	return 0;
}

整数类型:shortintlong

修饰符:signed有符号)、unsigned无符号)。

long long 目标类型至少有64位的宽度。

如以下代码:

#include<iostream>
using namespace std;
int main(int argc, const char* argv[])
{
	signed int number1 = -100;		//有符号数
	unsigned int number2 = 100;		//无符号数
	cout << number1 << endl;
	return 0;
}

字符类型:char

浮点类型:floatdouble。

如以下代码:

#include<iostream>
using namespace std;
int main(int argc, const char* argv[])
{
	float number1 = 1.1;	//单精度浮点数
	double number2 = 2.2;	//双精度浮点数
	return 0;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值