#include<iostream>
using namespace std;
int main()
{
cout << "hello world!" << endl;
return 0;
system("pause");
}
基本数据类型:
短整型 | short int | 2 | -2^15~2^15-1 | |
整型 | 整型 | int | 4 | -2^31~2^31-1 |
长整型 | long int | 4 | -2^31~2^31-1 | |
字符型 | char | 1 | -2^7~2^7-1 | |
单精度型 | float | 4 | -2^31~2^31-1 | |
浮点型 | 双精度型 | double | 8 | -2^63~2^63-1 |
双长精度型 | long double | 8 | -2^63~2^63-1 | |
布尔型 | bool | 1 | -2^7~2^7-1 |
- 字符常量只能包括一个字符, 如′ AB ′ 是不合法的。
- 字符常量区分大小写字母, 如′ A ′ 和′ a ′ 是两个不同的字符常量。
- 每一个小写字母比它相应的大写字母的ASCII代码大32
- "a"是字符串常量,′ a ′ 是字符常量。前者占两个字节,后者占1个字节
- endl表示换行
- sizeof:计算类型大小的一个关键字 cout<<sizeof(int)<<endl; 输出为4
- 不带符号(unsigned)的数据只能用来表示正数;带符号的,数据既有正数又有负数
- 一行定义多个变量时不能连着定义 charc1=c2=c3='A' 编译失败
- strlen:求字符串有效长度的函数,不包括最后的\0 cout << strlen("hello") << endl; 输出为 5 cout << strlen("c:\txt\123main")<< endl; \t和\ddd为转义符,输出为10
-
int a=3.13 输出为a=3,发生了隐式类型转换
-
cout << "\"hello world\""<< endl; 输出为"hello word"
-
cout << '\65'<< endl; 8进制65=5*8^0+6*8^1=53(十进制),53对应字符'5',所以输出为5 \ddd 1~3位八进制数
-
\n 换行 \t 水平制表符 \r回车
-
'A'——65 'a'——97 '0'——48 \n——10 \t——9 \r——13 空格——32
-
符号常量 #define PI 3.14
#include<iostream> using namespace std; #define PI 3.14159 int main() { double r = 2.0; cout << PI*r*r << endl;//计算圆面积 cout << 2 * PI*r << endl;//计算圆周长 return 0; }
-
c+中const定义的是常量,不能被修改 const int a=100;