首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

数据结构中定长门类与不定长类型

2012-09-11 
数据结构中定长类型与不定长类型请问数据结构中定长类型为什么不能销毁呢? 而不定长必须得销毁呢?它们之间

数据结构中定长类型与不定长类型
请问数据结构中定长类型为什么不能销毁呢? 而不定长必须得销毁呢?它们之间有什么区别呢?

[解决办法]
定长在栈上,不定长在堆上。

这是个简单的说法。
[解决办法]

C/C++ code
#include <stdio.h>#include <stdlib.h>#include <string.h>struct node_st {        char *str1;        char str2[10];};int main(int argc, char* const argv[]) {        struct node_st node;        node.str1 = (char*)malloc(10);        free(node.str1);        struct node_st *pnode;        pnode = (struct node_st*)malloc(sizeof(struct node_st));        pnode->str1 = (char*)malloc(10);        free(pnode->str1);        free(pnode);        return 0;}你说这些谁在栈上, 谁在堆上, 谁是定长, 谁是不定长? 本来就没有固定的搭配,要学会原理,自己分析设计。
[解决办法]
探讨
C/C++ code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node_st {
char *str1;
char str2[10];
};

int main(int argc, char* const argv[]) {
struc……

[解决办法]
学习下 堆内存和栈内存 就懂了
[解决办法]
{,}
malloc,free
new,delete
生,死

热点排行