C语言 c++ php mysql nginx linux lnmp lamp lanmp memcache redis 面试 笔记 ppt 设计模式 问题 远程连接

do break的妙用

 

#include <stdio.h>
#include <malloc.h>

int func(int n)
{
  //资源的统一申请
int i = 0; int ret = 0; int* p = (int*)malloc(sizeof(int) * n); do { if( NULL == p ) break; if( n < 0 ) break; for(i=0; i<n; i++) { p[i] = i; printf("%d\n", p[i]); } ret = 1; }while(0);
  //资源的统一释放
free(p); return ret; } int main() { if( func(10) ) { printf("OK"); } else { printf("ERROR"); } }

 

posted on 2015-07-20 22:32  思齐_  阅读(454)  评论(0编辑  收藏  举报