一,常量
常量有两种表示方法:
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