前言
我们知道Python、Java等编程语言在进行对象管理时,往往将对象分配在堆内存中。而c/c++中的对象(结构体)数据存储则更灵活。
正文
比如在c/c++中,定义一个结构体对象,表示字符串链表的节点。
typedef struct string_node{
char* str;
struct string_node* next;
}string_node;
/* 用于增加链表节点 */
void add_string_node_to_list(string_node* head,char* str){
string_node* node = (string_node*)malloc(sizeof(string_node));
node->str = (char*)malloc(sizeof(char)*strlen(str)+1);