谁能解释一下下面的c代码吗?

标签 c pointers struct

谁能告诉我下面的c代码是什么意思?

我想知道为什么声明为 struct 的变量 mesg 再次在末尾给出一个指针。

struct mesg 
 { 
 long type; 
 char mtext[MAX]; 
 } *mesg;

最佳答案

*mesg 中的

mesg 是指向 struct mesg 类型变量的指针。

例如,

struct mesg 
 { 
 long type; 
 char mtext[MAX]; 
 } abc;

此处,abc 表示 struct mesg 类型的变量。

同样,

struct mesg 
 { 
 long type; 
 char mtext[MAX]; 
 } *mesg;
*mesg 中的

mesg 表示指向 struct mesg 类型变量的指针。

如果您使用其他名称作为变量名称,也许会更容易,例如

struct mesg 
 { 
 long type; 
 char mtext[MAX]; 
 } *m;

这里,m是一个指向struct mesg类型变量的指针。

关于谁能解释一下下面的c代码吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26840376/

相关文章:

C 链接器未按预期运行

创建一个 GUI 来绘制 Linux 中的 CPU 使用率

c - 声明指向 3 x 3 数组的指针并使用指针打印它

c - 段错误(核心转储)——如何修复我的代码?

c++ - 访问特定结构成员时程序崩溃

c - 通过char数组中的token获取参数

c - 如何使用 NativeCall 缓解 Rakudo 中的错误?

C "comparison between pointer and integer"菜单警告

xml - 高语 : Refactoring xml tag definition in struct

parsing - 使用 viper 解析 YAML 时如何使用动态 key ?