C --goto跳转语句

在C语言中,goto是一条无条件跳转语句,它允许程序控制流跳转到同一函数内的某个特定标签处继续执行。使用goto语句时,需要在目标位置定义一个标签,标签由一个标识符后跟一个冒号(:)组成

 

 

#include <iostream>
using namespace std;

void func(bool b) {
    if (b==true){
        goto label;
    }
    else {
        goto label1;
    }
label:
    cout << "" << endl;
    return;
label1:
    cout << "" << endl;
    return;
}

int main()
{
    /*
    goto语句:可以让CPU跳转到任何一条语句去执行
    语法:goto 标签
    */
    func(1);
    return 0;
}

 

 

 

posted @ 2020-08-12 07:50  天子骄龙  阅读(276)  评论(0)    收藏  举报