1.入口条件循环和出口条件循环之间的区别是什么?各种C++循环分别属于其中的哪一种?
C++提供了3种循环:for、while和do while循环。for和while循环都是入口条件循环,意味着程序将在执行循环体中的语句之前检查测试条件。do while循环是出口条件循环,意味着其将在执行循环体中的语句之后检查条件。
2.如果下面的代码片段是有效程序的组成部分,它将打印什么内容?
int i;
for(i = 0;i < 5;i++)
   cout << i;
   cout << endl;答案:
//2
#if 1
#include<iostream>
using namespace std;
int main()
{
	int i;
	for (i = 0; i < 5; i++)
		cout << i;
	    cout << endl;
	system("pause");
	return 0;
}
#endif
3.如果下面的代码片段是有效程序的组成部分,它将打印什么内容?
int j;
for(j = 0;j < 11;j += 3)
    cout << j;
cout << endl << j << endl;答案:
//3
#if 1
#include<iostream>
using namespace std;
int main()
{
	int j;
	for (j = 0; j < 11; j += 3)
		cout << j;
	cout << endl << j << endl;
	system("pause");
	return 0;
}
#endif
4.如果下面的代码片段是有效程序的组成部分,它将打印什么内容?
int j = 5;
while(++j < 9)
   cout << j++ << endl;答案:
//4
#if 1
#include<iostream>
using namespace std;
int main()
{
	int j = 5;
	while (++j < 9)
		cout << j++ << endl;
	system("pause");
	return 0;
}
#endif
5.如果下面的代码片段是有效程序的组成部分,它将打印什么内容?
int k = 8;
do
   cout << "k = " << k << endl;
while(k++ < 5);答案:
//5
#if 1
#include<iostream>
using namespace std;
int main()
{
	int k = 8;
	do
	   cout << "k = " << k << endl;
	while (k++ < 5);
	system("pause");
	return 0;
}
#endif
6.编写一个打印1、2、4、8、16、32、64的for循环,每轮循环都将计数变量的值乘以2。
//6
#if 1
#include<iostream>
using namespace std;
int main()
{
	int i;
	for (i = 1; i < 64; i *= 2)
		cout << i << "、";
	cout << i << endl;
	system("pause");
	return 0;
}
#endif7.如何在循环体中包括多条语句?
将语句放在一对大括号中形成一个复合语句或代码块。
8.下面的语句是否有效?如果无效,原因是什么?如果有效,它将完成什么工作?
int x = (1,024);
下面的语句呢?
int y;
y = 1,024;两条语句都有效。
第一条语句中,表达式x = (1,024)由两个表达式组成——1和024,用逗号运算符连接。值为右侧表达式的值。这是024,八进制为20,因此该声明将值20赋给x。
第二条语句中,运算符优先级将其判定成:(y = 1),024;即,左侧表达式将y设置为1。
9.在查看输入方面,cin >> ch同cin.get(ch)和ch = cin.get()有什么不同?
cin >> ch;将跳过空格、换行符和制表符,其他两种格式将读取这些字符。



















