C在函数返回语句 [英] the return statement of C in a function

查看:136
本文介绍了C在函数返回语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C语言的一个新手,我有一个关于用C 收益语句问题:

 无效verifyValue(int值)
{
   返回;
}无效handleValue(int值)
{
   开关(值)
   {
      情况1:
         // 做一点事
         打破;      案例10:
         verifyValue(值);
         // code第1部分的其余部分
         打破;
      默认:
         打破;
   }
}诠释的main()
{
   INT vlaue = 10;
   handleValue(值);   // code部分2的其余部分
}

所以 verifyValue()函数将返回情况下,10 ,一旦返回,将$其余C $丙部1继续执行或code部分2的其余部分继续执行,从那里这回在 verifyValue()真的回来了?


解决方案

  10的情况下:
         verifyValue(值);
         // code第1部分的其余部分
         打破;

verifyValue()函数被调用,并从该函数返回后


  

// code部分,其余1


被执行。
休息后执行,所以你出去开关的结构。

后来,控制返回到的main()


  

// code部分,其余2


执行

I am a newbie of C language, I have a question about return statement in C:

void verifyValue(int value)
{
   return;
}

void handleValue(int value)
{
   switch(value)
   {
      case 1:
         // do something
         break;

      case 10:
         verifyValue(value);
         // the rest of code part 1
         break;
      default:
         break;           
   }
}

int main()
{
   int vlaue = 10;
   handleValue(value);

   // the rest of code part 2
}

so the verifyValue() function will return in case 10, once it returns, will the rest of code part 1 continue to execute or the rest of code part 2 continue to execute, from where this return in verifyValue() really returned?

解决方案

case 10:
         verifyValue(value);
         // the rest of code part 1
         break;

verifyValue() function is called and after returning from that function

// the rest of code part 1

is executed. After that break is executed so you get out of switch construct.

Later the control is returned to main() and

// the rest of code part 2

is executed.

这篇关于C在函数返回语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆