AcWing | 语法基础课 | 变量,输入输出和顺序语句
Hello word
#include <iostream>
using namespace std;
int main()
{
cout << "Hello word" << endl;
return 0;
}
第一部分打的头文件区,常用的头文件:#include 里面有printf,scanf函数,#include 里面有cin读入,cout读出。
第二部分using namespace std;一个大的c++项目会有重复名,namespace解决了相互文件的重命名。
第三部分int main();被称为函数的入口,最后的结尾一定要是return 0;
变量
bool类型变量存储值,ture/false。1byte char类型,存储字符。'c','a' ' ' 。 int类型,-2147483648-2147483647。4byte float类型,1.25,2.5,1.235e2,单精度浮点数,有效数字有6-7位。4byte double 15-16位有效数字。8byte longlong类型,整数类型。int的扩展板。-2^63 ~2^63-1 输出:lld。 long double 18-19位有效数字 1Byte =8bit;换算关系都是1024;
int a, b = 2, c = b;
char j = 'a', k = 'b';
变量的输入输出
#include <iostream>
using namespace std;
int main()
{
int a,b;
cin >> a >> b;//输入
cout << a + b << endl;//输出
return 0;
}
- cstdio
#include <cstdio>
using namespace std;
int main(){
int a,b;
scanf("%d %d",&a,&b);
printf("%d %d",a + b, a * b);///.1保留一位小数
return 0;
}
int: %d
float:%f
double:%lf
char:%c
long long:%lld