正在加载图片...
73函数的返回值例 例无返回值函数 void swap(int x, inty) maIn 返回语句 i int temp 形式: return(表达式); temp=X 或 return表达式; X-V 或 return; 功能:使程序控制从被调用函数返回 e y=temp 到调用函数中,同时把返值带}} 给调用函数 ts(本函数有问题 说明 函数中可有多个 return语句 (a+b<0 若无 return语句,遇}时, return ab: 自动返回调用函数 else if(atb==0) 若函数类型与 return语句中表达 eturn(a+b); 式值的类型不一致,按前者为准,sef 自动转换函数调用转换 printf("%d %d",a, b); return; void型函数– 返回语句 • 形式: return (表达式); 或 return 表达式; 或 return; • 功能:使程序控制从被调用函数返回 到调用函数中,同时把返值带 给调用函数 • 说明: – 函数中可有多个return语句 – 若无return语句,遇} 时, 自动返回调用函数 – 若函数类型与return语句中表达 式值的类型不一致,按前者为准, 自动转换------函数调用转换 – void型函数 7.3 函数的返回值 例 return 语句的示意 main() { int i=-4; int j=4; int aa=test(i, j); printf("%d",aa); getch(); } test (int a, int b) { if (a+b<0) return a*b; else if(a+b ==0) return (a+b); else { printf("%d %d",a,b); } return; } 例 无返回值函数 void swap(int x,int y ) { int temp; temp=x; x=y; y=temp; } (本函数有问题!!) *
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有