阅读背景:

C语言中的浅拷贝和深拷贝

来源:互联网 

浅拷贝

首先看下面这段代码:

# include<assert.h>
# include<string.h>
#include <stdlib.h>
typedef struct Node//定义了一个结构体
{
	int size;
	char *data;
}S_Node;
int main()
{
	S_Node node1;
	node1.data = (char *)malloc(sizeof(char)*100);//指针所指向的地址
	assert(node1.data != NULL);
	strcpy(node1.data, "hello world");
	node1.size = strlen(node1.data);
	S_Node node2 = node1;
	printf("%d, %s\n", node1.size, node1.data);
	printf("%d,%s\n", node2.size, node2.data);
	free(node1.data);
	# include<assert.h>
# includ



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: