C中,在struct中,得到一个可变大小的数组
2006-10-15 17:56
369 查看
#include <stdio.h>
struct xx{
int i;
char st[1];
};
int main()
{
char s1[]="abc";
struct xx *a=(struct xx*)malloc(sizeof(struct xx)+strlen(s1)+1);
strcpy(a->st, s1);
printf("%s ", a->st);
free(a);
getch();
return 0;
}
详细内容见《深度探索C++对象模型》P19
http://community.csdn.net/Expert/topic/5054/5054882.xml?temp=.9214289
struct xx{
int i;
char st[1];
};
int main()
{
char s1[]="abc";
struct xx *a=(struct xx*)malloc(sizeof(struct xx)+strlen(s1)+1);
strcpy(a->st, s1);
printf("%s ", a->st);
free(a);
getch();
return 0;
}
详细内容见《深度探索C++对象模型》P19
http://community.csdn.net/Expert/topic/5054/5054882.xml?temp=.9214289
相关文章推荐
- 使struct对象拥有可变大小的数组——(C++深度探索)
- 笔试题:一个整数的“真数”,是将它的各个位相加得到的和。写一个函数完成一个数组按真数大小排序
- C++使struct对象拥有可变大小的数组(详解)
- 关于理解《C++ 对象模型》中:把单一元素的数组放在末尾,struct可以拥有可变大小的数组
- struct实现拥有可变大小的数组
- 使struct对象拥有可变大小的数组
- 实现一个函数,传递一个有10个已经排好序的整形元素数组(数组大小实际为11)中,将一个指定的值按顺序插入,并在main函数中将插入后的数组输出。
- sizeof应用于虚参形式的数组时,得到的结果是4(指针大小) k&r 5-4
- 一个长度可变的数组结构体的用法(命名空间的用法)
- 用C++的模板类定义一个万能数组,数组元素类型任意,数组大小也任意
- 一个可变布局列表,有9种布局item大小,每个item可拖拽切换位置
- c语言学习笔记(4)struct和union:柔性数组存储斐波那契数列以及union判断系统大小端
- 写一个函数,随机地从大小为n的数组中选取m个整数。要求每个元素被选中的概率相等。
- asp.net 得到一个文件夹下的所有文件夹及子文件夹名,得到所有文件名,文件大小,文件夹大小
- 偏移了一个数组的大小
- C++得到一个数组的最大递减数组({3,9,4,5,0}得到结果是{9,4,0})
- c中数组大小不能用变量的一个解决办法
- 【C++学习】通过输入数来确定一个数组的动态大小
- OC中动态创建可变数组的问题.有一个数组,数组中有13个元素,先将该数组进行分组,每3个元素为一组,分为若干组,最后用一个数组统一管理这些分组.(要动态创建数组).两种方法
- 求一个数组相邻数的最大和,并且得到开始编号和结束编号(原创)