05 2015 档案
摘要:z=(a>b)?a:b如果a>b为真,则z=a;如果a>b为假,则z=b;
阅读全文
摘要:与 &&或 ||非 !优先级 not and or
阅读全文
摘要:a++ a-- (先使用,后加减)++a --a (先加减,后使用)
阅读全文
摘要:赋值运算符 =加法运算符 +减法运算符 -乘法运算符 *除法运算符 /求模运算符 %
阅读全文
摘要:用于计算值的操作都可以看作是表达式,表达式总能返回一个值,如:1+2;
阅读全文
摘要:块以左大括号“{”开始,以右大括号“}”结束,中间允许放置多条语句。{a=b;b=c;a=c;}
阅读全文
摘要:枚举型常量用enum来定义enum num{zero,one,two,three,four};例子:#includeusing namespace std;int main(){ enum day { sunday,monday,tuesday,wednesday,thur...
阅读全文
摘要:常量值不能改变,对常量初始化以后不能再对其进行赋值const double PI=3.1415926用const来定义常量
阅读全文
摘要:定义整形变量int a;给整形变量复制a=1;定义整形变量的时候赋值int a=1;例子:#includeusing namespace std;int main(){ int a = -1; unsigned b = -2; short c = -3; long d = -...
阅读全文
摘要:char 型变量可以存储一个字节的字符,只能用来保存英文字符和标点符号。存储汉字、韩文与日文不可以,因为这个文字占据有两个字节。C++引入 wchar_t 类型(双字节类型,又名宽字符类型)来解决定义宽字符wchar_t wt[]=L"中";定义了一个wchar_t类型的数组变量wt,用来保存中文字...
阅读全文
摘要:字符型变量存放的是字符,字符指的是计算机字符集中的ASCII码。字符型变量只占一个字节。定义字符型变量char ch;给字符变量赋值ch='A';(字符型变量必须用单引号)例子:#includeusing namespace std;int main(){ char ch; ch = '...
阅读全文
摘要:定义布尔型变量bool check;对布尔型变量赋值check=1;或者check=true;在定义布尔型变量时直接初始化赋值bool check=true;例子:#includeusing namespace std;int main(){ bool check; check = tr...
阅读全文
摘要:计算机的内存就像一个一个的小文件柜,每个文件柜有许多小格子组成,每个格子都有编号,这个编号就是内存地址。有的编号上面贴的有标签,这个标签就是变量名。变量一般放置在一个或者多个格子里。所以,知道了变量名就可以找个变量的值。
阅读全文
摘要: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号