Chinaunix
标题:
知道这段代码的输出吗?
[打印本页]
作者:
grep_one
时间:
2008-03-21 16:52
标题:
知道这段代码的输出吗?
#include <stdlib.h>
#include <string>
#include <stdio.h>
#define size 5
main()
{
char *xx[size] =
{
"zhangsan",
"lisi",
"maozedong",
"zhaoliu",
"wangwu"
};
char **choices = 0;
int i;
choices = (char **)alloca((sizeof(const char *) * size) + 1);
for(i=0; i < size; i++) {
char heading[4];
sprintf(heading, "%d: ", i);
heading[3] = '\0';
std::string str;
str += heading;
str += xx;
choices = (char *)str.c_str();
}
choices = NULL;
for(int k=0; k< size; k++) {
if(choices[k]) {
fprintf(stdout, "%s\n", choices[k]);
//free(choices[k]);
}
}
}
复制代码
[
本帖最后由 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