C++学习第二课
来源:互联网 发布:凸优化求解算法 编辑:程序博客网 时间:2024/06/05 00:35
今天会把我学习过的知识都总结下来,有一些会简要带过,重点记录那些让我豁然开朗的内容。PS,马上就要开题了,希望自己好好加油!
类型限定符:const(恒定) volatile(不稳定的) restrict(指针类型,唯一不重叠)
存储类型符:auto register static extern mutable
操作符: + - * / % ++ -- == != < > <= >= = += -= *= /= %= && || ! & | ^ << >> ~
sizeof condition? X:Y ,(comma) cast .(dot) ->(arrow) *(pointer) &(address)
eg: cast 强制转换类型 int(2.2200)=2
循环: while() do{ }while( ) for( ; ; ){ } break continue goto
条件判断: switch(){ case1:0 break;} if if else
函数调用: call by value,call by pointer,call by reference
指针调用是C和C++共有的,引用调用是C++所特有的,效果等同于指针调用,可以改变被调用的量,一般都采用这种方式,指针调用易出错(不容易检查出来)
下面是引用调用实例:
#include <iostream>using namespace std;int swap(int &,int &);int main(){ int a=3,b=4; swap(a,b); cout << "a:" << a << endl; cout << "b:" << b << endl; return 0;} int swap(int &x,int &y){ int rent; rent=x; x=y; y=rent; return 0;}
a,b显示的最终结果分别是4,3,这表明引用调用可以改变被调用的值。
指针调用:
#include <iostream>using namespace std;void swap(int *,int *);int main(){ int a=3,b=4; swap(&a,&b); cout << "a:" << a << endl; cout << "b:" << b << endl; return o;} void swap(int *x,int *y){ int rent; rent=*x; *x=*y; *y=rent; return 0;}
数学表达式:
cos sin tan log(底数为e) pow hypot sqrt abs fabs floor(取整)
随机数的产生:
#include <iostream>#include <ctime>#include <cstdlib>using namespace std; int main (){ int i,j; // set the seed srand( (unsigned)time( NULL ) ); /* generate 10 random numbers. */ for( i = 0; i < 10; i++ ) { // generate actual random number j= rand(); cout <<" Random Number : " << j<< endl; } return 0;}
<cstdlib>包含rand,srand函数,产生随机函数必须得有一个种子,用srand产生。为了使每次产生的随机数不一样,需要利用到当前时间。
倘若srand()一样,则产生的随机数是一样的,如下图:
#include <iostream>#include <cstdlib>using namespace std;int main(){ int i,j; for(i=0;i<10;i++) { srand(1); j=rand(); cout << j; } return 0;}
倘若 srand(1)置于int i,j 的上一行,则产生的随机数也是不一样的。
- 学习c第二天
- Objective-C学习第二天
- 第二章《开始学习C++》
- 学习Objective-C第二天
- c语言学习第二天
- 学习C语言第二天
- C语言学习第二天
- C语言学习第二章
- 实训学习课——C#(第二篇)
- 学习c语言第二课(基本数据类型)
- C语言学习第二课:数据处理与交互式输入
- 第二课 C语言
- C语言第二课
- Linux C第二课
- C语言第二课
- 第二课、C简介
- C专家编程第二章学习笔记
- C 学习笔记3 第二天
- 使用友盟分享,出现linker command failed with exit code 1
- JavaScript基础——面向对象的程序设计
- Go 语言项目管理
- 操作系统7- shell
- oto餐饮app实时订单物流追踪系统架构设计(一)
- C++学习第二课
- “undefined JNI_GetCreatedJavaVM”和“File format not recognized”错误原因分析
- zoj 1395 可行遍性问题
- 网络 思科
- zabbix采集软件指标实现方法
- ios NSString md5 base64 urlEncode isEmail
- 修改项目名称
- 浅谈strtok函数的使用心得
- [Leetcode]Add Two Numbers