Ⅰ变量、常量、标识符命名规则、关键字
常量:define const
Ⅱ数据类型
1、数据类型存在的意义:给变量分配合适的内存空间 2、整型:  3、sizeof关键字 4、实型:  5、字符型 6、转义字符:  7、字符串型:
char str1[] = "hello world";
string str2 = "hello world";
8、布尔类型:  9、数据的输入 cin >> 变量
Ⅲ运算符
1、算术运算符 2、赋值运算符 3、比较运算符 4、逻辑运算符
Ⅳ程序流程结构
1、单行if语句 2、多行if语句 3、多条件if语句 4、嵌套if语句 5、三目运算符(在c++中三目运算符返回的是变量,可以继续赋值) 6、switch语句
7、while语句+猜数字 8、dowhile语句+水仙花数 9、for语句+敲桌子 10、嵌套循环+乘法口诀表 11、break、continue、goto
Ⅴ数组
1、一维数组定义、数组名(可以统计整个数组在内存中的长度;首地址)+ 五只小猪称体重、数组元素逆置、冒泡排序 2、二维数组定义、数组名(查看二维数组所占空间;首地址)+ 考试成绩统计
Ⅵ函数
1、函数的定义、调用、值传递、常见样式、声明 2、函数的分文件编写 
Ⅶ指针
1、指针的定义 **2、指针所占用的空间:**在32位操作系统下,指针是占4个字节空间大小;64位,8个字节 **3、空指针:是不可以进行访问的,0 ~ 255之间的内存编号是系统占用内存,不允许用户访问 4、野指针: 例子:int p = (int)0x1100; 5、const修饰指针: ①常量指针 const int * p = &a; 特点:指针的指向可以改,指针指向的值不能改 ②指针常量 int * const p = &a; 特点:指针的指向不可以改,指针指向的值不可以改  ③ const int * const p = &a;
6、指针和数组 7、指针和函数 ①值传递 ②地址传递
8、指针、数组、函数
void bubbleSort(int *arr,int len)
{
for (int i = 0; i < len - 1; i++)
{
for (int j = 0; j < len - i - 1; j++)
{
if (arr[j] > arr[j + 1])
{
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
void printArray(int* arr, int len)
{
for (int i = 0; i < len - 1; i++)
{
cout << arr[i] << endl;
}
}
int main()
{
int arr[10] = { 4,3,6,9,1,2,10,8,7,5 };
int len = sizeof(arr) / sizeof(arr[0]);
bubbleSort(arr, len);
printArray(arr, len);
return 0;
}
Ⅷ结构体
1、结构体的定义和使用 struct 结构体名 { 结构体成员列表 };
struct Student
{
string name;
int age;
int score;
};
int main()
{
2、结构体数组 struct 结构体名 数组名[ 元素个数 ] = { {}, {},…{} };
struct Student
{
string name;
int age;
int score;
};
int main()
{
struct Student stuArray[3] =
{
{"zhangsan",19,100},
{"lisi",28,99},
{"wangwu",38,66},
};
stuArray[2].name = "zhaoliu";
stuArray[2].age = 80;
stuArray[2].score = 60;
for (int i = 0; i < 3; i++)
{
cout << "姓名: " << stuArray[i].name
<< "年龄:" << stuArray[i].age
<< "分数:" << stuArray[i].score << endl;
}
system("pause");
}
3、结构体指针
struct student
{
string name;
int age;
int score;
};
int main()
{
struct student s = { "zhangsan",18,100 };
struct student * p = &s;
cout << "姓名:" << p->name
<< " 年龄:" << p->age << " 分数: "
<< p->score << endl;
system("pause");
}
4、结构体嵌套结构体
struct student
{
string name;
int age;
int score;
};
struct teacher
{
int id;
string name;
int age;
struct student stu;
};
int main()
{
struct teacher t;
t.id = 10000;
t.name = "老王";
t.age = 50;
t.stu.name = " 小王";
t.stu.age = 20;
t.stu.score = 60;
cout << "老师姓名:" << t.name
<< " 老师编号:" << t.id
<< " 老师年龄:" << t.age
<< " 老师辅导的学生姓名:" << t.stu.name
<< " 学生年龄:" << t.stu.age
<< " 学生分数:" << t.stu.score << endl;
system("pause");
}
5、结构体做函数参数
struct student
{
string name;
int age;
int score;
};
void printStudent1(struct student s)
{
cout << "姓名: " << s.name
<< " 年龄: " << s.age
<< " 分数: " << s.score << endl;
}
void printStudent2(struct student* p)
{
p->age = 200;
cout << "姓名: " << p->name
<< " 年龄: " << p->age
<< " 分数: " << p->score << endl;
}
int main()
{
struct student s;
s.name = "zhangsan";
s.age = 20;
s.score = 85;
printStudent1(s);
printStudent2(&s);
system("pause");
}
6、结构体中const使用场景
struct student
{
string name;
int age;
int score;
};
void printStudent(const struct student *p)
{
cout << "姓名: " << p->name
<< " 年龄: " << p->age
<< " 分数: " << p->score << endl;
}
int main()
{
struct student s = { "张三",15,70 };
printStudent(&s);
system("pause");
}
7、结构体案例
struct Student
{
string sName;
int score;
};
struct Teacher
{
string tName;
struct Student sArray[5];
};
void allocateSpace(struct Teacher tArray[],int len)
{
string nameSeed = "ABCDE";
for (int i=0;i<len;i++)
{
tArray[i].tName = "Teacher_";
tArray[i].tName += nameSeed[i];
for (int j = 0; j < 5; j++)
{
tArray[i].sArray[j].sName = "Student_";
tArray[i].sArray[j].sName += nameSeed[j];
int random = rand() % 61 + 40;
tArray[i].sArray[j].score = random;
}
}
}
void printInfo(struct Teacher tArray[], int len)
{
for (int i = 0; i < len; i++)
{
cout << "老师姓名:" << tArray[i].tName << endl;
for (int j = 0; j < 5; j++)
{
cout << "\t学生姓名: " << tArray[i].sArray[j].sName
<< " 考试分数:" << tArray[i].sArray[j].score << endl;
}
}
}
int main()
{
srand((unsigned int)time(NULL));
struct Teacher tArray[3];
int len = sizeof(tArray) / sizeof(tArray[0]);
allocateSpace(tArray, len);
printInfo(tArray, len);
system("pause");
}
struct Hero
{
string name;
int age;
string sex;
};
void bubbleSort(struct Hero herroArray[], int len)
{
for (int i = 0; i < len - 1; i++)
{
for (int j = 0; j < len - i - 1; j++ )
{
if (herroArray[j].age > herroArray[j + 1].age)
{
struct Hero temp = herroArray[j];
herroArray[j] = herroArray[j + 1];
herroArray[j + 1] = temp;
}
}
}
}
int main()
{
struct Hero heroArray[5] =
{
{"liubei",23,"nan"},
{"guanyu",22,"nan"},
{"zhangfei",20,"nan"},
{"zhaoyun",21,"nan"},
{"diaochan",19,"nv"},
};
int len = sizeof(heroArray) / sizeof(heroArray[0]);
bubbleSort(heroArray, len);
for (int i = 0; i < len; i++)
{
cout << "姓名: " << heroArray[i].name
<< " 年龄: " << heroArray[i].age
<< " 性别: " << heroArray[i].sex << endl;
}
system("pause");
}
【ps: 多行注释:crtl+shift+/】
|