我是靠谱客的博主 精明歌曲,这篇文章主要介绍C语言 goto语句,现在分享给大家,希望可以做个参考。

goto语句又叫无条件转移语句,先看一个例子:

#include <stdio.h>
void main()
{
    if ( 1 )
    {
        goto gotoflag;
    }
    printf( "hello " );
    gotoflag: printf( "nihao" );
}

输出:

nihao

可以看出在执行 goto gotoflag 语句之后直接跳转到gotoflag:printf("nihao");

gotoflag:为标记行,冒号切记不可省略。

反之如果代码这样子

#include <stdio.h>

void main()
{
    if ( 0 )
    {
        goto gotoflag;
    }
    printf( "hello " );
    gotoflag: printf( "nihao" );
}

输出:

hello nihao

可以看到执行了

printf(“hello “);
gotoflag:printf(“nihao”);

这两条语句,gotoflag:将没有意义。

最后

以上就是精明歌曲最近收集整理的关于C语言 goto语句的全部内容,更多相关C语言内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(49)

评论列表共有 0 条评论

立即
投稿
返回
顶部