Chinaunix

标题: 知道这段代码的输出吗? [打印本页]

作者: grep_one    时间: 2008-03-21 16:52
标题: 知道这段代码的输出吗?
  1. #include <stdlib.h>
  2. #include <string>
  3. #include <stdio.h>

  4. #define size 5

  5. main()
  6. {
  7.   char *xx[size] =
  8.   {
  9.     "zhangsan",
  10.     "lisi",
  11.     "maozedong",
  12.     "zhaoliu",
  13.     "wangwu"
  14.   };

  15.   char **choices = 0;
  16.   int i;
  17.   choices = (char **)alloca((sizeof(const char *) * size) + 1);
  18.   for(i=0; i < size; i++) {
  19.     char heading[4];
  20.     sprintf(heading, "%d: ", i);
  21.     heading[3] = '\0';
  22.     std::string str;
  23.     str += heading;
  24.     str += xx;
  25.     choices = (char *)str.c_str();
  26.   }
  27.   choices = NULL;

  28.   for(int k=0; k< size; k++) {
  29.     if(choices[k]) {
  30.       fprintf(stdout, "%s\n", choices[k]);
  31.       //free(choices[k]);
  32.     }

  33.   }

  34. }
复制代码


[ 本帖最后由 grep_one 于 2008-3-21 16:55 编辑 ]
作者: evaspring    时间: 2008-03-21 20:42
不知道,请教高人~
作者: 北斗星君    时间: 2008-03-22 10:27
编译,执行 不就知道了嘛?




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2