栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

数据类型笔记

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

数据类型笔记

数据类型 整型

int 21亿多

long long

浮点型、实型

double

字符型

char

//字符=>ASCII码
#include
using namespace std;
int main ()
{
	char a; 
	cin >> a;
	cout << (int)a << endl;
	return 0;
 } 
字符串型

C语言

//char 字符串名[]
//等号后面 要用双引号 包含起来字符串
char str1[]="Hello world";
cout < 

C++语言

//添加一个头文件   
#include 
string str2 ="hello world";
布尔类型bool

只占用一个字节

true——真(本质是1)

false——假(本质是2)

#include
using namespace std;
int main ()
{
//1、创建bool数据类型 
	bool flag = true ; //true代表真
	cout << flag < 
//创建字符型,要用''
//单一字符
#include
using namespace std;
int main ()
{
	char ch='a';//创建字符型,要用''
	cout< 
//ASCII码=>字符
#include
using namespace std;
int main ()
{
	int a; 
	cin >> a;
	cout << (char)a << endl;//强制转换
	return 0;
 } 

ASCII码

a——97

A——65

转义字符

换行符 n

水平制表符 t 占8个位

输出

数据的输入

cin

char ch = 'a';
cout << ch;
cin >> ch;
cout << ch;
//绝对值大于等于1,即为真,其余为假。
#include
#include
using namespace std;
int main ()
{    
    bool flag = true ;
	cout << flag ;
	
	cin >> flag ;
	cout << flag << endl ;
	system (" pause") ;
	return 0; 
    
}  
数据类型转换 隐式类型转换
short、char =>int->unsinged int ->long->unsinged long->float=>double->long double

=>表示必转换

->表示类型不同时转换

转换以赋值号左边的变量类型为主 例
# include 
# include 
using namespace std ;

int main () {
	int x = -1;
	unsigned y = 2;
	printf("%d", x / y);
	return 0 ;
}

说明:因为xy运算时,y为 unsigned类型,所以x也要被转换为
d类型,类型转换不改变内存中的值,-1在内存中对应的 unsigned是一个很大的整数,所以除以2后也是一个很大的整数

强制类型转换
int x;
(double)x//x强制转换成double类型
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/290111.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号