关于程序的注释及变量的意义:
#include<iostream>
using namespace std;
int main() {
int a = 10;
cout << "a=" << a << endl;
cout << "hhhhhh" << endl;
system("pause");
return 0;
}
关于常量:
#include<iostream>
using namespace std;
#define day 7
int main() {
cout << "一周总共有:" << day << "天" << endl;
const int month = 12;
cout << "一年总共有:" << month << "月" << endl;
system("pause");
return 0;
}
关于数据类型:
#include<iostream>
using namespace std;
#include<string>
int main() {
short num1 = 10;
cout << "short所占的内存大小:" << sizeof(num1) << endl;
float f1 = 3.14f;
cout << "f1=" << f1 << endl;
double d1 = 4.11;
cout << "d1=" << d1 << endl;
float f2 = 3e2;
cout << "f2=" << f2 << endl;
char ch = 'a';
cout << ch <<" 字符型变量所占内存"<<sizeof(char)<<endl;
cout << (int)ch << endl;
cout << "hello world\n" ;
cout << "//" << endl;
system("pause");
cout << "aaa\thello world" << endl;
char str[] = "hello world";
cout << str << endl;
string str2 = "hhhhhh";
cout << str2 << endl;
bool flag = true;
cout << flag << endl;
int a = 0;
cout << "请给a赋值" << endl;
cin >> a;
cout <<"a="<< a << endl;
return 0;
}
关于运算符:
#include<iostream>
using namespace std;
int main() {
int a1 = 10;
int b1 = 3;
cout << a1 + b1 << endl;
cout << a1 - b1 << endl;
cout << a1 * b1 << endl;
cout << a1 / b1 << endl;
double d1 = 0.5;
double d2 = 0.2;
cout << d1 / d2 << endl;
int a2 = 10;
int b2 = 3;
cout << a2 % b2 << endl;
int a3 = 10;
int b3 = ++a3 * 10;
cout << "a3=" << a3 << endl;
cout <<"b3="<< b3 << endl;
int a4 = 10;
int b4 = a4++ * 10;
cout << "a4=" << a4 << endl;
cout << "b4=" << b4 << endl;
int a = 10;
a %= 2;
cout << "a=" << a << endl;
int b = 10;
cout << !b << endl;
int c = 0;
cout <<( b && c) << endl;
cout << (b || c) << endl;
system("pause");
return 0;
}