c语言函数

2018-07-31  本文已影响4人  卿人丶

[if !supportLists]1.     [endif]值传递:(单向传递实参->形参)关于函数调用过程中形参和实参  实参的值不改变形参只是在函数调用过程中的所临时开辟的储存空间,因此两者的为不同的存储单元函数所用的也仅仅只是返回值而已

[if !supportLists]2.     [endif]函数声明过程中其形参名可以省略反正个人认为不省挺好的  毕竟清楚

[if !supportLists]3.     [endif]递归函数的运用

#include

int main()

{

    intage(int);

    for (int i= 1; i <= 5; i++)

    {

       printf("%d\n",age(i));

    }

}

int age(int n)

{

    if (n ==1)

    {

       return10;

    }

    else

    {

       returnage(n - 1)+2;

    }

}

递归调用求n的阶乘 n!

int aa(int n)

{

    if (n ==1)

    {

       return1;

    }

    else{

       returnaa(n - 1)*n;

    }

}

[if !supportLists]4. [endif]数组名 作为参数传递 其实参和形参一一对应 相应的也变化

介绍一下 关于比较大小的排序方法

void sort(int array[], int n)

{

    int temp;

    int flag;

    for (int i= 0; i < n - 1; i++)

    {

       temp =i;

       for(int j = i+1; j < n; j++)

       {

           if(array[j]

           {

              temp= j;

           }

       }

       flag =array[temp];

       array[temp]= array[i];

       array[i]= flag;

    }

}

上一篇 下一篇

猜你喜欢

热点阅读