C语言函数
Posted 新起点1
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C语言函数相关的知识,希望对你有一定的参考价值。
#include <stdio.h> int main() { int count1 =1; do{ int count2 =0; ++count2; printf("\ncount1=%d count2=%d",count1,count2); count1++; }while (count1<=8); printf("\n count1=%d\n",count1); return 0; }
不等价于下面这个,尽管两个输出一样
#include <stdio.h> int main() { int count1 =1; do{ int count2 =0; ++count2; printf("\ncount1=%d count2=%d",count1,count2); }while (++count1<=8); printf("\n count1=%d\n",count1); return 0; }
详情见下面这个例子
#include <stdio.h> int main(void) { int count= 0; do{ int count =0; ++count ; printf("\n count=%d",count ); } while (++count<=8); printf("\n count =%d\n",count ); return 0; } /* count=0 count=0 count=1 dayin count=1<=8 count=0 count=1 dayin !! count=2<=8 ... count=0 count=1 dayin count=8<=8 count=0 count=1 dayin count=9 wo tiao count=9 shuchu 关键在于while 中的count 和do while 里面的不是一回事,while 使用的是那个外面的,do{}的count出了括号就死了 作用域就是这么回事,以大括号为界限,出来就死。 生存期就是,就活一轮,下一轮就重生 */
#include <stdio.h> float average(float x ,float y) { return (x+y)/2.0f; } int main (void) { float value1=0.0F; float value2=0.0F; float value3=0.0F; printf("Enter two floating-point values separated by blanks:\n"); scanf("%f %f",&value1,&value2); value3=average (value1,value2); printf("\n The average is:%f\n",value3); return 0; }/* 函数调用例子*/
#include <stdio.h> float average(float x ,float y);/* 也可以写做 float average (float ,float); */ int main (void) { float value1=0.0F; float value2=0.0F; float value3=0.0F; printf("Enter two floating-point values separated by blanks:\n"); scanf("%f %f",&value1,&value2); value3=average (value1,value2); printf("\n The average is:%f\n",value3); return 0; } float average(float x ,float y) { return (x+y)/2.0f; }
以上是关于C语言函数的主要内容,如果未能解决你的问题,请参考以下文章
Qt编程遇到的问题,我在qt中直接使用C语言的程序片段,有问题 ,求解
我的C语言学习进阶之旅解决 Visual Studio 2019 报错:错误 C4996 ‘fscanf‘: This function or variable may be unsafe.(代码片段
我的C语言学习进阶之旅解决 Visual Studio 2019 报错:错误 C4996 ‘fscanf‘: This function or variable may be unsafe.(代码片段