在 C 中将一个结构分配给另一个 [英] Assign one struct to another in C

查看:30
本文介绍了在 C 中将一个结构分配给另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能不能将一个结构体的一个实例分配给另一个,像这样:

Can you assign one instance of a struct to another, like so:

struct Test t1;
struct Test t2;
t2 = t1;

我看到它适用于简单的结构,但它适用于复杂的结构吗?
编译器如何知道如何根据类型复制数据项,即区分 int 和字符串?

I have seen it work for simple structures, bu does it work for complex structures?
How does the compiler know how to copy data items depending on their type, i.e. differentiating between an int and string?

推荐答案

是,如果结构类型相同.将其视为内存副本.

Yes if the structure is of the same type. Think it as a memory copy.

这篇关于在 C 中将一个结构分配给另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆