C++学习note1(常量,sizeof关键字,科学计数法,转义字符)

一,常量

常量有两种表示方法:

1.宏常量                              #define +变量名+ 变量值

2.const修饰的变量              const+ 类型+变量名=变量值

代码示例:

include<iostream>
using namespace std;

#define Day 7        /宏常量:main外
int main(){
	  

	const int month = 12;     /const修饰的变量(也为常量)
	cout<<"there are "<< Day <<" days in a week."<<endl;
	system("pause");
	return 0;
}

二,sizeof

用法:sizeof(数据类型/已经定义数据类型的量)

代码示例:

#include<iostream>
using namespace std;


int main(){

	short num1=10;
	cout<<"short占用的内存空间为:"<<sizeof(num1)<<endl;

	system("pause");
	return 0;
}

 三,科学计数法

代码示例:

#include<iostream>
using namespace std;

int main(){

	int a=3e2;
	float b=3e-2;
	cout<<a<<endl;
	cout<<b<<endl;

	system("pause");
	return 0;
}
300
0.03

ps: c++中浮点型最多显示六位数

四,转义字符

作用:用于表示一些不能直接显示出来的ASCII字符

换行符:\n

反斜杠:\\

水平制表符:\t(补齐八位)

#include<iostream>
using namespace std;

int main(){

    cout<<"hello world\n";

	cout<<"\\"<<endl;

	cout<<"aaa\t666"<<endl;
	cout<<"aaaaaa\t666"<<endl;
	cout<<"aaaaa\t666"<<endl;
	cout<<"a\t666"<<endl;
	
	system("pause");
	return 0;
}
hello world
\
aaa     666
aaaaaa  666
aaaaa   666
a       666

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值