《C++ Primer Plus》第5章学习笔记

2021-06-07  本文已影响0人  蓬篙人

内容思维导图

第5章 循环和关系表达式

1. for循环

for (initialization; test_expression; update-expression)
    body

2. 关系表达式

操作符 含义
< 小于
> 大于
<= 小于或等于
>= 大于或等于
== 等于
!= 不等于
// 其中word为字符数组,下面的语句是判断word数组的地址与字符串常量"mate"的地址是否相同
word == "mate";
char big[80] = "Daffy";
char little[6] = "Daffy";

3. while循环

while (test-condition)
    body

4. do while循环

do
    body
while (test-expression);

5. 循环和文本输入

char ch;
cin.get(ch);                  // read a char
while (cin.fail() == false)   // test for EOF
{
    // do something
    cin.get(ch);             // read another char
}

6. 嵌套循环和二维数组

int maxtemps[4][5];
// 一维数组初始化
int buts[5] = { 23, 26, 24, 31, 28 };
// 二维数组初始化
int maxtemps[2][5] =
{
    { 94, 98, 87, 103, 101 },
    { 98, 99, 91, 107, 105 }
}
// 字符指针数组初始化
const char* cities[2] = 
{
    "Gribble City",
    "New Gribble"
}
上一篇 下一篇

猜你喜欢

热点阅读