做了个goto的测试:
void function(int n){
if(n==1){
goto error;
}else{
printf("other\n");
}
printf("i'm here!\n");
error:printf("error is here\n");
printf("end\n");
}
假设
function(1)
//当n==1,满足if条件,那么跳到语句标号error处执行,执行完标号处语句,继续向下执行
结果:
error is here
end
Press any key to continue
假设
function(3)
//当n==3,那么就会执行else里面的语句,而且之后向下执行,连标号处的也跟着执行
//打印结果:
other
i'm here!
error is here
end
Press any key to continue
看了下goto的说法:无条件跳转。通过这次实验,我觉得这个语句标号只当一个标识,正常情况下,当语句执行过来,不会阻断他的执行,就是说他和普通语句没啥区别,唯一有区别的是他和goto结合才能显现出功能,that's all!