c语言set,C语言中的setjump()和longjump()

在本节中,我们将看到什么是C中的setjump和跳远踏板setjump()和longjump()位于SETJMP.H库。这两个函数的语法如下。setjump(jmp_buf buf) : uses buf to store current position and returns 0.

longjump(jmp_buf buf, i) : Go back to place pointed by buf and return i.

这些在C中用于异常处理。该setjump()可作为try块,并且longjump()可以作为throw语句。该longjump()转移控制由指向的足尖setjump()。

在这里,我们将看到如何在不使用递归,循环或宏扩展的情况下将数字打印100次。在这里,我们将使用setjump()和longjump()方法。

示例#include 

#include 

jmp_buf buf;

main() {

int x = 1;

setjmp(buf); //set the jump position using buf

printf("5"); // Prints a number

x++;

if (x <= 100)

longjmp(buf, 1); // Jump to the point located by setjmp

}

输出结果5555555555555555555555555555555555555555555555555555555555555555555555555555

555555555555555555555555

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值