随笔分类 - C/C++课程
摘要:int a;a=1;或者:int a=1;定义一个变量以后,系统便会为这个变量分配一个内存地址,这样当我们为这个变量赋值时,数据便会通过这个地址写入到内存中。
阅读全文
摘要:在任意函数外部定义的变量叫全局变量,全局变量也在main函数外部,这种变量对程序中的任何函数都有效。#includeusing namespace std;int x = 3, y = 4;//函数全局变量void func();int main(){ cout << "在main函数中,X:...
阅读全文
摘要:在函数内部声明的变量为局部变量,该变量只存活于该函数中#includevoid show(int);int main(){ int x = 1; show(x); std::cout << x << std::endl; return 0;}void show(int x){...
阅读全文
摘要:函数可以先声明后定义,如下:#includeint show(int, int);//函数声明int main(){ int a = 1, b = 2, c; c = show(a, b); std::cout << c << std::endl;}//函数定义int show(i...
阅读全文
摘要:函数可以返回一个值,也可以不返回值。不返回值是定义为voidvoid show(){ std::cout << "Hello World!";}如果返回一个整数int show(int a,int b){ return a + b;}
阅读全文
摘要:给函数传递参数#includeint show(int a,int b){ return a + b;}int main(){ int a = 1, b = 2, c; c = show(a, b); std::cout << c << std::endl;}
阅读全文
摘要:函数又叫方法,即实现某项功能或服务的代码块void show(){ std::cout void show(){ std::cout << "Hello World!" << std::endl;}int main(){ show(); return 0;}
阅读全文
摘要:使用命名空间,可以避免重名问题例如:#includenamespace a{ int x = 8;}namespace b{ int x = 9;}int main(){ int x = 10; std::cout << a::x << b::x << x << std::e...
阅读全文
摘要:如果用iostream则需要加命名空间;如果用iostream.h则不需要加命名空间;示例:#includeusing namespace std;int main(){ cout int main(){ cout << "Hello World!"; return 0;}
阅读全文
摘要:std:: 是命名空间标识符,C++标准库中的函数或者对象都是在命名空间std中定义的cout是标准库所提供的一个对象,因此在使用cout时要用std::cout如果不喜欢重复使用std,可以使用:using std::cout;using std::endl;#includeusing std::...
阅读全文
摘要:C++中使用 cout 来输出,cout是一个对象,存在与 iostream 中,因此要先引入该文件例子:std::coutint main(){ std::cout << "Hello World!"; return 0;}
阅读全文
摘要:#includeint main(){ std::cout << "Hello World!"; return 0;}
阅读全文

浙公网安备 33010602011771号