摘要:
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;} 阅读全文