第零章的题目很简单,入门性质,基本是个人都能写出来。。。
0-1 计算3+4的值,但不输出。
0-2 源代码:
#include <iostream>
int main()
{
std::cout<<"This (\") is a quote , and this (\\) is a backslash."
<<std::endl;
return 0;
}
0-3 "\t"代表输出" ".如"This (\") is a quote ,\tand this (\\) is a backslash."
This (") is a quote , and this (\) is a backslash
0-4 源代码:
#include <iostream>
using namespace std;
int main()
{
cout<<"include<iostream>"<<endl;
cout<<"using namespace std;"<<endl;
cout<<"int main()"<<endl;
cout<<"{"<<endl;
cout<<"cout<<\"hello world!\"<<endl;"<<endl;
cout<<"return 0;"<<endl;
cout<<"}"<<endl;
return 0;
}
0-6 是一个有效程序,运行结果为:Hello, world!
0-7 注释错误,因为注释符号/*和*/在C++编译器中不支持嵌套,所以只能识别第一个/*和第一个*/符号,后面的汉子字符不作为注释部分,无法识别。
0-8 有效。//符号为对行注释,不存在嵌套问题。
0-9 源代码:int main(){}
0-10 源代码:
#include <iostream>
int
main
(
)
{
std
::
cout
<<
"Hello world!"
<<
std
::
endl
;
return
0
;
}