c程序设计基础函数学习教案_第1页
c程序设计基础函数学习教案_第2页
c程序设计基础函数学习教案_第3页
c程序设计基础函数学习教案_第4页
c程序设计基础函数学习教案_第5页
已阅读5页,还剩345页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、会计学1c程序设计基础函数程序设计基础函数 3.1 函数的定义与调用 3.2 函数参数的传递 3.3 函数调用机制 3.4 函数指针 3.5 内联函数和重载函数 3.6 变量存储特性与标识符作用域 3.7 多文件结构程序 3.8 命名空间 3.9 终止程序执行 小结第1页/共350页函数参数返回值输入流输出流第2页/共350页 函数作用 任务划分;代码重用 函数是C+程序的重要组件 第3页/共350页 函数定义由两部分组成:函数首部和函数操作描述 函数调用是通过表达式或语句激活并执行函数代码的过程 / 求圆柱体体积#includeusing namespace std ;double volu

2、me ( double radius, double height ) return 3.14 * radius * radius * height ; int main() double vol, r, h ; cin r h ; vol = volume ( r, h ) ; cout Volume = vol endl ;第4页/共350页 函数定义由两部分组成:函数首部和函数操作描述 函数调用是通过表达式或语句激活并执行函数代码的过程 / 求圆柱体体积#includeusing namespace std ;double volume ( double radius, double h

3、eight ) return 3.14 * radius * radius * height ; int main() double vol, r, h ; cin r h ; vol = volume ( r, h ) ; cout Volume = vol endl ;函数定义第5页/共350页 函数定义由两部分组成:函数首部和函数操作描述 函数调用是通过表达式或语句激活并执行函数代码的过程 / 求圆柱体体积#includeusing namespace std ;double volume ( double radius, double height ) return 3.14 * ra

4、dius * radius * height ; int main() double vol, r, h ; cin r h ; vol = volume ( r, h ) ; cout Volume = vol endl ;函数调用第6页/共350页函数定义形式 类型 函数名 ( 形式参数表 ) 语句序列 3.1.1 函数定义 第7页/共350页函数定义形式 类型 函数名 ( 形式参数表 ) 语句序列 3.1.1 函数定义 函数头函数接口,包括:第8页/共350页函数定义形式 函数名 ( 形式参数表 ) 语句序列 3.1.1 函数定义 函数头函数接口,包括: 函数体中由 return 语句返

5、回的值的类型。没有 返回值其类型为void第9页/共350页函数定义形式 类型 ( 形式参数表 ) 语句序列 3.1.1 函数定义 函数头函数接口,包括:函数返回值类型 函数体中由 return 语句返回的值的类型。没有 返回值其类型为void 用户定义标识符第10页/共350页函数定义形式 类型 函数名 ( ) 语句序列 3.1.1 函数定义 函数头函数接口,包括:函数返回值类型 函数体中由 return 语句返回的值的类型。没有 返回值其类型为void函数名 用户定义标识符 逗号分隔的参数说明表列,缺省形式参数时不 能省略圆括号。一般形式为:类型 参数1 ,类型 参数2 , ,类型 参数n

6、 第11页/共350页函数定义形式 3.1.1 函数定义 函数头函数接口类型 函数名 ( 形式参数表 ) 函数的实现代码。第12页/共350页例3-1 3.1.1 函数定义 void printmessage ( ) cout How do you do! endl ; 第13页/共350页例3-13.1.1 函数定义 void printmessage ( ) cout How do you do! endl ; 函数返回值类型无返回值第14页/共350页例3-13.1.1 函数定义 void printmessage ( ) cout How do you do! endl ; 函数名第1

7、5页/共350页例3-13.1.1 函数定义 void printmessage ( ) cout How do you do! endl ; 形式参数表无参数第16页/共350页例3-13.1.1 函数定义 void printmessage ( ) cout How do you do! y ) return x ; else return y ; 第18页/共350页例3-23.1.1 函数定义 double max ( double x , double y ) if ( x y ) return x ; else return y ; 函数返回值类型第19页/共350页例3-23.1

8、.1 函数定义 double max ( double x , double y ) if ( x y ) return x ; else return y ; 函数名第20页/共350页例3-23.1.1 函数定义 double max ( double x , double y ) if ( x y ) return x ; else return y ; 形式参数表第21页/共350页例3-23.1.1 函数定义 double max ( double x , double y ) if ( x y ) return x ; else return y ; 函数体第22页/共350页例3

9、-23.1.1 函数定义 double max ( double x , double y ) if ( x y ) return x ; else return y ; 返回值return 语句形式: 表达式 或 (表达式 )作用: 返回函数值 不再执行后续语句,程序控制返回调用点 一个函数体内可以有多个return 语句 表达式 返回值的类型与函数类型不相同时, 自动强制转换成函数的类型第23页/共350页例3-23.1.1 函数定义 double max ( double x , double y ) if ( x y ) return x ; else return y ; Funct

10、ionName () / statements ; FunctionName () / statements ; /可省略第24页/共350页调用形式 函数名 ( 实际参数表 )3.1.2 函数调用第25页/共350页调用形式 ( 实际参数表 )3.1.2 函数调用 函数的入口地址第26页/共350页调用形式 函数名 ( )3.1.2 函数调用函数名 函数的入口地址 与形式参数必须在个数、类型、位置一一对应第27页/共350页调用形式 函数名 ( 实际参数表 )3.1.2 函数调用函数名 函数的入口地址实际参数表 与形式参数必须在个数、类型、位置一一对应第28页/共350页3.1.2 函数调用

11、#includeusing namespace std ;void printmessage () cout How do you do! endl ; int main() printmessage() ; 例3-1第29页/共350页3.1.2 函数调用#includeusing namespace std ;void printmessage () cout How do you do! endl ; int main() printmessage() ; 函数调用语句例3-1第30页/共350页3.1.2 函数调用例3-2#includeusing namespace std ;dou

12、ble max ( double x , double y ) if ( x y ) return x ; else return y ; int main() double a, b; cin a b ; double m = max( a, b ); cout max( m, 3.5 ) endl ; 第31页/共350页3.1.2 函数调用例3-2#includeusing namespace std ;double max ( double x , double y ) if ( x y ) return x ; else return y ; int main() double a,

13、 b; cin a b ; double m = max( a, b ); cout max( m, 3.5 ) endl ; 函数调用表达式第32页/共350页3.1.2 函数调用例3-2#includeusing namespace std ;double max ( double x , double y ) if ( x y ) return x ; else return y ; int main() double a, b; cin a b ; double m = max( a, b ); cout max( m, a+3.5 ) endl ; cout max( , ) end

14、l ;实际参数是表达式第33页/共350页3.1.3 函数原型 函数原型的作用是告诉编译器有关函数的信息:函数的名字函数返回的数据类型函数要接受的参数个数、参数类型和参数的顺序 编译器根据函数原型检查函数调用的正确性 函数原型的形式:类型 函数名 ( 形式参数表 );第34页/共350页3.1.3 函数原型 函数原型的作用是告诉编译器有关函数的信息:函数的名字函数返回的数据类型函数要接受的参数个数、参数类型和参数的顺序 编译器根据函数原型检查函数调用的正确性 函数原型的形式:类型 函数名 ( 形式参数表 );函数原型是声明语句第35页/共350页3.1.3 函数原型#include using

15、 namespace std ;double max( double, double ) ;/ 函数原型int main() double a, b, c, m1, m2 ; cout a b c ; m1 = max( a, b ) ;/ 函数调用 m2 = max( m1, c ) ; cout Maximum = m2 y ) return x ; else return y ; 使用函数原型第36页/共350页3.1.3 函数原型#include using namespace std ;double max( double, double ) ;/ 函数原型int main() do

16、uble a, b, c, m1, m2 ; cout a b c ; m1 = max( a, b ) ;/ 函数调用 m2 = max( m1, c ) ; cout Maximum = m2 y ) return x ; else return y ; 函数原型的参数表不需要参数名使用函数原型第37页/共350页3.1.3 函数原型#include using namespace std ;double max( double, double ) ;/ 函数原型int main() double a, b, c, m1, m2 ; cout a b c ; m1 = max( a, b

17、) ;/ 函数调用 m2 = max( m1, c ) ; cout Maximum = m2 y ) return x ; else return y ; 函数调用出现在定义之前函数原型声明是必须的使用函数原型第38页/共350页3.1.3 函数原型函数定义在调用之前#include using namespace std ;double max( double x, double y )/ 函数定义 if ( x y ) return x ; else return y ; int main() double a, b, c, m1, m2 ; cout a b c ; m1 = max(

18、 a, b ) ;/ 函数调用 m2 = max( m1, c ) ; cout Maximum = m2 endl ;第39页/共350页3.1.3 函数原型函数定义在调用之前#include using namespace std ;double max( double x, double y )/ 函数定义 if ( x y ) return x ; else return y ; int main() double a, b, c, m1, m2 ; cout a b c ; m1 = max( a, b ) ;/ 函数调用 m2 = max( m1, c ) ; cout Maxim

19、um = m2 endl ;函数定义出现在调用之前无必要作函数原型声明第40页/共350页3.1.3 函数原型函数原型函数原型说明说明int abs( int n );n的绝对值的绝对值double cos( double x );x(弧度)的余弦(弧度)的余弦double exp( double x );指数函数,指数函数,exdouble fabs( double x );x的绝对值的绝对值double fmod( double x, double y );x/y的浮点余数的浮点余数double log( double x );x的自然对数(以的自然对数(以e为底)为底)double lo

20、g10( double x );x的对数(以的对数(以10为底)为底)double pow( double x, double y );求幂,求幂,xydouble sin( double x );x(弧度)的正弦(弧度)的正弦double sqrt( double x );x的平方根的平方根double tan( double x );x(弧度)的正切(弧度)的正切 cmath中几个常用的数学函数 第41页/共350页3.1.3 函数原型/ 例3-3 用库函数求正弦和余弦值#include #include using namespace std ;int main() double PI

21、= 3.1415926535; double x, y; x = PI/ 2; y = sin( x ); cout sin( x ) = y endl ; y = cos( x ); cout cos( x ) = y endl ;第42页/共350页3.1.3 函数原型/ 例3-3 用库函数求正弦和余弦值#include #include using namespace std ;int main() double PI = 3.1415926535; double x, y; x = PI / 2; y = sin( x ); cout sin( x ) = y endl ; y = c

22、os( x ); cout cos( x ) = y endl ;包含头文件第43页/共350页3.1.3 函数原型/ 例3-3 用库函数求正弦和余弦值#include #include using namespace std ;int main() double PI = 3.1415926535; double x, y; x = PI / 2; y = sin( x ); cout sin( x ) = y endl ; y = cos( x ); cout cos( x ) = y endl ;调用库函数第44页/共350页第45页/共350页C+有三种参数传递机制:值传递指针传递引用

23、传递 第46页/共350页3.2.1传值参数 调用函数时,实参表达式的值被复制到相应形参标识的对象中, 并按形参类型强制转换 函数内对形参的访问、修改,都在形参的标识对象进行 函数返回时,形参对象被撤消,不影响实参的值 值传送的实参可以是常量、有确定值的变量或表达式 函数返回值通过匿名对象传递 第47页/共350页/ 例3-4 强制类型转换#includeusing namespace std ;int main ( ) double add1 ( double , double ) ; / 函数原型 double add2 ( int , int ) ; / 函数原型 double a ,

24、b, c ; cin a b ; c = add1 ( a , b ) ; cout c1= c endl ; c = add2 ( 1/a , 1/b) ; cout c2= c endl ;double add1 ( double x , double y ) return ( x + y ) ; double add2 ( int i , int j ) return ( i + j ) ; 3.2.3.2.第48页/共350页/ 例3-4 强制类型转换#includeusing namespace std ;int main ( ) double add1 ( double , dou

25、ble ) ; / 函数原型 double add2 ( int , int ) ; / 函数原型 double a , b, c ; cin a b ; c = add1 ( a , b ) ; cout c1= c endl ; c = add2 ( 1/a , 1/b) ; cout c2= c endl ;double add1 ( double x , double y ) return ( x + y ) ; double add2 ( int i , int j ) return ( i + j ) ; 类型强制转换截取整数部分传送给形参3.2.3.2.第49页/共350页#in

26、cludeusing namespace std ;int add(int , int ) ;int main() int a, b, c ; cin a b; c = add(a,b) ; cout c = c endl ;int add(int i, int j ) i + + ; j + + ; return ( i + j ); / 例3-5 值参传递3.2.3.2.第50页/共350页#includeusing namespace std ;int add(int , int ) ;int main() int a, b, c ; cin a b; c = add(a,b) ; co

27、ut c = c endl ;int add(int i, int j ) i + + ; j + + ; return ( i + j ); abc int a, b, c ;/ 例3-5 值参传递3.2.3.2.第51页/共350页#includeusing namespace std ;int add(int , int ) ;int main() int a, b, c ; cin a b; c = add(a,b) ; cout c = c a b;/ 例3-5 值参传递3.2.3.2.第52页/共350页#includeusing namespace std ;int add(in

28、t , int ) ;int main() int a, b, c ; cin a b; c = add(a,b) ; cout c = c endl ;int add(int i, int j ) i + + ; j + + ; return ( i + j ); abc24 c = add(a,b) ;/ 例3-5 值参传递3.2.3.2.第53页/共350页#includeusing namespace std ;int add(int , int ) ;int main() int a, b, c ; cin a b; c = add(a,b) ; cout c = c endl ;i

29、nt add(int i, int j ) i + + ; j + + ; return ( i + j ); abcij2424 int add(int i, int j )/ 例3-5 值参传递3.2.3.2.第54页/共350页24ij#includeusing namespace std ;int add(int , int ) ;int main() int a, b, c ; cin a b; c = add(a,b) ; cout c = c endl ;int add(int i, int j ) i + + ; j + + ; return ( i + j ); abc242

30、4 i + + ; j + + ;/ 例3-5 值参传递3.2.3.2.第55页/共350页#includeusing namespace std ;int add(int , int ) ;int main() int a, b, c ; cin a b; c = add(a,b) ; cout c = c endl ;int add(int i, int j ) i + + ; j + + ; return ( i + j ); abcij2424obj return ( i + j );/ 例3-5 值参传递3 + 53.2.3.2.第56页/共350页abcij2424obj8/ 例3

31、-5 值参传递3.2.3.2.#includeusing namespace std ;int add(int , int ) ;int main() int a, b, c ; cin a b; c = add(a,b) ; cout c = c endl ;int add(int i, int j ) i + + ; j + + ; return ( i + j ); return ( i + j );第57页/共350页#includeusing namespace std ;int add(int , int ) ;int main() int a, b, c ; cin a b; c

32、 = add(a,b) ; cout c = c endl ;int add(int i, int j ) i + + ; j + + ; return ( i + j ); abcij24824 c = add(a,b) ;/ 例3-5 值参传递obj83.2.3.2.第58页/共350页abc248/ 例3-5 值参传递3.2.3.2.#includeusing namespace std ;int add(int , int ) ;int main() int a, b, c ; cin a b; c = add(a,b) ; cout c = c endl ;int add(int i

33、, int j ) i + + ; j + + ; return ( i + j ); c = add(a,b) ;第59页/共350页#includeusing namespace std ;int add(int , int ) ;int main() int a, b, c ; cin a b; c = add(a,b) ; cout c = c endl ;int add(int i, int j ) i + + ; j + + ; return ( i + j ); abc248输出c = 8 cout c = c endl ;/ 例3-5 值参传递3.2.3.2.第60页/共350

34、页例3-6 计算圆筒的体积分析: 分别定义函数求不同几何体的体积 圆柱体的体积 = r2hdouble CylinderVolume(double r, double h ) ; 圆筒的体积 = 外圆柱体的体积 内圆柱体的体积 double DonutSize(double Outer, double Inner, double Height) ;3.2.3.2.第61页/共350页/ 通过参数半径 r 和高度 h,返回圆柱体体积double CylinderVolume( double r, double h ) const double PI = 3.1415; return PI * r

35、 * r * h;/ 通过参数外圆柱体半径 Outer,内圆柱体半径 Inner / 和圆柱体高度 Height 返回圆筒体积double DonutSize(double Outer, double Inner, double Height) double OuterSize = CylinderVolume(Outer, Height); double HoleSize = CylinderVolume(Inner, Height); return OuterSize - HoleSize;3.2.3.2.例3-6 计算圆筒的体积第62页/共350页/ 通过参数半径 r 和高度 h,返回圆

36、柱体体积double CylinderVolume( double r, double h ) const double PI = 3.1415; return PI * r * r * h;/ 通过参数外圆柱体半径 Outer,内圆柱体半径 Inner / 和圆柱体高度 Height 返回圆筒体积double DonutSize(double Outer, double t Inner, double Height) double OuterSize = CylinderVolume(Outer, Height); double HoleSize = CylinderVolume(Inner

37、, Height); return OuterSize - HoleSize;3.2.3.2.例3-6 计算圆筒的体积第63页/共350页#includeusing namespace std ;double CylinderVolume( double r, double h );double DonutSize(double Outer, double Inner, double Height);int main() double OuterRadius, InnerRadius, Height; cout OuterRadius ; cout InnerRadius ; cout Hei

38、ght ; cout size of the donut is : DonutSize( OuterRadius, InnerRadius, Height) endl ;double CylinderVolume( double r, double h ) const double PI = 3.1415; return PI * r * r * h;double DonutSize(double Outer, double Inner, double Height) double OuterSize = CylinderVolume(Outer, Height); double HoleSi

39、ze = CylinderVolume(Inner, Height); return OuterSize - HoleSize;3.2.3.2.例3-6 计算圆筒的体积第64页/共350页#includeusing namespace std ;double CylinderVolume( double r, double h );double DonutSize(double Outer, double Inner, double Height);int main() double OuterRadius, InnerRadius, Height; cout OuterRadius ; co

40、ut InnerRadius ; cout Height ; cout size of the donut is : DonutSize( OuterRadius, InnerRadius, Height) endl ;double CylinderVolume( double r, double h ) const double PI = 3.1415; return PI * r * r * h;double DonutSize(double Outer, double Inner, double Height) double OuterSize = CylinderVolume(Oute

41、r, Height); double HoleSize = CylinderVolume(Inner, Height); return OuterSize - HoleSize;函数原型3.2.3.2.例3-6 计算圆筒的体积第65页/共350页#includeusing namespace std ;double CylinderVolume( double r, double h );double DonutSize(double Outer, double Inner, double Height);int main() double OuterRadius, InnerRadius,

42、Height; cout OuterRadius ; cout InnerRadius ; cout Height ; cout size of the donut is : DonutSize( OuterRadius, InnerRadius, Height) endl ;函数定义3.2.3.2.例3-6 计算圆筒的体积第66页/共350页#includeusing namespace std ;double CylinderVolume( double r, double h );double DonutSize(double Outer, double Inner, double He

43、ight);int main() double OuterRadius, InnerRadius, Height; cout OuterRadius ; cout InnerRadius ; cout Height ; cout size of the donut is : DonutSize( OuterRadius, InnerRadius, Height) endl ;double CylinderVolume( double r, double h ) const double PI = 3.1415; return PI * r * r * h;double DonutSize(do

44、uble Outer, double Inner, double Height) double OuterSize = CylinderVolume(Outer, Height); double HoleSize = CylinderVolume(Inner, Height); return OuterSize - HoleSize;调用函数3.2.3.2.例3-6 计算圆筒的体积第67页/共350页#includeusing namespace std ;double CylinderVolume( double r, double h );double DonutSize(double O

45、uter, double Inner, double Height);int main() double OuterRadius, InnerRadius, Height; cout OuterRadius ; cout InnerRadius ; cout Height ; cout size of the donut is : DonutSize( OuterRadius, InnerRadius, Height) endl ;double CylinderVolume( double r, double h ) const double PI = 3.1415; return PI *

46、r * r * h;double DonutSize(double Outer, double Inner, double Height) double OuterSize = CylinderVolume(Outer, Height); double HoleSize = CylinderVolume(Inner, Height); return OuterSize - HoleSize;3.2.3.2.例3-6 计算圆筒的体积第68页/共350页 C+没有规定在函数调用时实际参数的求值顺序 若实际参数表达式之间有求值关联,同一个程序在不同编译器可能 产生不同的运行结果第69页/共350页#

47、includeusing namespace std ;int add ( int x , int y ) return x + y ; int main ( ) int x = 4 , y = 6 ; int z = add ( + x , x + y ) ; cout 5 + 11 = z ?!n ;第70页/共350页#includeusing namespace std ;int add ( int x , int y ) return x + y ; int main ( ) int x = 4 , y = 6 ; int z = add ( , ) ; cout 5 + 11 =

48、z ?!n ;xyz46xy 10第71页/共350页46xyz56xy105#includeusing namespace std ;int add ( int x , int y ) return x + y ; int main ( ) int x = 4 , y = 6 ; int z = add ( , ) ; cout 5 + 11 = z ?!n ;第72页/共350页#includeusing namespace std ;int add ( int x , int y ) return x + y ; int main ( ) int x = 4 , y = 6 ; int

49、z = add ( , ) ; cout 5 + 11 = z ?!n ;xyz565xy10obj5 + 10第73页/共350页#includeusing namespace std ;int add ( int x , int y ) return x + y ; int main ( ) int x = 4 , y = 6 ; int z = add ( , ) ; cout 5 + 11 = z ?!n ;xyz565xy105 + 10obj 15第74页/共350页#includeusing namespace std ;int add ( int x , int y ) ret

50、urn x + y ; int main ( ) int x = 4 , y = 6 ; int z = add ( , ) ; cout 5 + 11 = z ?!n ;xyz565xy10obj 15第75页/共350页#includeusing namespace std ;int add ( int x , int y ) return x + y ; int main ( ) int x = 4 , y = 6 ; int z = add ( , ) ; cout 5 + 11 = z ?!n ;xyz56第76页/共350页#includeusing namespace std ;

51、int add ( int x , int y ) return x + y ; int main ( ) int x = 4 , y = 6 ; int z = add ( , ) ; cout 5 + 11 = z ?!n ; int z = add ( , x + y ) ; cout 5 + 11 = z n ;第77页/共350页 C+允许指定传值参数的默认值。当函数调用中省略默认参数时, 默认值自动传递给被调用函数 默认参数在函数原型定义 默认参数放在一般参数之后 第78页/共350页/ 例3-7 使用默认参数#includeusing namespace std ;double

52、power ( double real, int n = 2 ) ;int main ( ) double r = 3.0 ; cout power ( r ) endl ; cout power ( r, 3 ) endl ;double power ( double real , int n ) if ( n = 0 ) return 1.0 ; double result = real ; for ( int i = 2 ; i = n ; i + ) result *= real ; return result;第79页/共350页/ 例3-7 使用默认参数#includeusing

53、namespace std ;double power ( double real, ) ;int main ( ) double r = 3.0 ; cout power ( r ) endl ; cout power ( r, 3 ) endl ;double power ( double real , int n ) if ( n = 0 ) return 1.0 ; double result = real ; for ( int i = 2 ; i = n ; i + ) result *= real ; return result;定义默认参数第80页/共350页/ 例3-7 使用

54、默认参数#includeusing namespace std ;double power ( double real, int n = 2 ) ;int main ( ) double r = 3.0 ; cout endl ; cout power ( r, 3 ) endl ;double power ( double real , int n ) if ( n = 0 ) return 1.0 ; double result = real ; for ( int i = 2 ; i = n ; i + ) result *= real ; return result;使用默认参数pow

55、er ( r,2 )第81页/共350页/ 例3-7 使用默认参数#includeusing namespace std ;double power ( double real, ) ;int main ( ) double r = 3.0 ; cout power ( r ) endl ; cout endl ;double power ( double real , int n ) if ( n = 0 ) return 1.0 ; double result = real ; for ( int i = 2 ; i = n ; i + ) result *= real ; return

56、result;不使用默认参数第82页/共350页 ;void delay ( int k , int time = ) ;第83页/共350页int f ( ) ;void delay ( int k , int time = f ( ) ) ;void ferror1 ( int x , , int z ) ;第84页/共350页int f ( ) ;void delay ( int k , int time = f ( ) ) ;void ferror1 ( int x , , int z ) ;void ferror2 ( int x , int y = 0 ) ;void ferror

57、2 ( int x ) ;/ 调用哪个函数 ? 第85页/共350页 形参指针对应的实际参数是地址表达式,即对象的指针 实际参数把对象的地址值赋给形式参数名标识的指针变量 被调用函数通过形参指针间接访问实参所指对象 3.2.2 指针参数3.2.3.2.第86页/共350页/ 例3-8 交换对象的值#includeusing namespace std ;void swap ( int * , int * ) ;int main () int a = 3 , b = 8 ; cout a = a , b = b endl ; swap ( &a , &b ) ; cout aft

58、er swapping. n ; cout a = a , b = b endl ;void swap ( int * x , int * y ) int temp = * x ; * x = * y ; * y = temp ;3.2.2 指针参数3.2.3.2.第87页/共350页/ 例3-8 交换对象的值#includeusing namespace std ;void swap ( , ) ;int main () int a = 3 , b = 8 ; cout a = a , b = b endl ; swap ( , ) ; cout after swapping. n ; co

59、ut a = a , b = b endl ;void swap ( , ) int temp = * x ; * x = * y ; * y = temp ;3a8bxy3.2.2 指针参数3.2.3.2.第88页/共350页3a8bxy3.2.2 指针参数3.2.3.2./ 例3-8 交换对象的值#includeusing namespace std ;void swap ( , ) ;int main () int a = 3 , b = 8 ; cout a = a , b = b endl ; swap ( , ) ; cout after swapping. n ; cout a

60、= a , b = b endl ;void swap ( , ) int temp = * x ; * x = * y ; * y = temp ;第89页/共350页3a8bxy3.2.2 指针参数3.2.3.2./ 例3-8 交换对象的值#includeusing namespace std ;void swap ( , ) ;int main () int a = 3 , b = 8 ; cout a = a , b = b endl ; swap ( , ) ; cout after swapping. n ; cout a = a , b = b endl ;void swap ( , ) int temp = * x ; * x = * y ; * y = temp ;第90页/共35

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论