码迷,mamicode.com
首页 > 其他好文 > 详细

函数注意

时间:2014-09-14 23:36:17      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:style   color   io   os   使用   div   sp   on   c   

返回值的基本概念、return的作用
   return
l   1>void可以省略return
l   2>可以多次使用return
l   3>return后面不能有其他语句
4. 函数的弱语法
l   如果没有写返回值类型,默认是int
l   如果写了返回值,可以不返回
l   可以调用一个没有定义过的函数
 
          返回值:
          0:正常退出
          1:异常退出
 
      函数注意点:
     1>不能嵌套定义函数
     2>死循环调用,自己调自己
     3>不能重复定义、可以重复声明
          
   
 
 
 

void test1()
{
    return;//或者将return去掉
}

 
int test2()
{
    // 返回值是int类型,因此return后面应该跟上一个整数
    return 0; // 这个0仅仅是随便写的,具体返回什么值,应该根据业务逻辑
    // return;
}
 
void test1()
{
}

void test2(int n)
{
}

int main()
{
    // test2接收的是int类型的参数,而test1没有返回值
    // 因此test1()不能作为test2的参数

    test2(10);
    //test2( test1() );
    return 0;
}

函数注意

标签:style   color   io   os   使用   div   sp   on   c   

原文地址:http://www.cnblogs.com/Alling/p/3971877.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!