本文共 769 字,大约阅读时间需要 2 分钟。
/*** @file LableAndGoto.cpp* @brief goto and lable, 测试goto和标号的关系* @note 试验结果, 标号也是有作用域的, 标号只在函数内部有效* 不同函数中有同名的标号,不影响程序有效和编译结果* 使用goto和标号, 使错误处理过程简洁, goto 仅限于函数内, 进行错误处理的跳转** 试验环境: winxpSp3 + vs2005Sp1*/#include "stdafx.h"void function1();void function2();void function3();int _tmain(int argc, _TCHAR* argv[]){ function1(); function2(); function3(); goto END; function1(); function2(); function3();END: /** run results function1(): a = 2 function2(): a = 3 function3(): a = 4 */ getchar(); return 0;}void function1(){ int a = 1; a++; goto END;END: _tprintf(_T("function1(): a = %d\n"), a);}void function2(){ int a = 2; a++; goto END;END: _tprintf(_T("function2(): a = %d\n"), a);}void function3(){ int a = 3; a++; goto END;END: _tprintf(_T("function3(): a = %d\n"), a);}
转载地址:http://wrlvf.baihongyu.com/