【问题标题】:What does it means when a pointer comes by the end of a variable (pointer*)?当指针位于变量(指针*)的末尾时,这意味着什么?
【发布时间】:2017-03-27 16:49:12
【问题描述】:

我已经了解过指针,但是当指针出现在像这样的变量的末尾时,这意味着什么。

struct student_record_node 
{
  struct class_record* record_;
  struct class_record_node* next_;
};

【问题讨论】:

  • by the end of a variable 哪个变量?
  • 它不在变量的末尾。 record_ 是变量 class_recordstruct 名称。
  • 这意味着您有一个指向该类型的指针,但指针位于类型的末尾,而不是变量。所以节点结构包含一个指向记录的指针,以及一个指向下一个记录节点的指针——它是一个单链表。
  • @DaveNewton 非常感谢。

标签: c pointers syntax structure


【解决方案1】:

这不是变量的结尾student_record_node 是用户定义的数据类型,使用 结构说明符 struct 关键字指定。

引用wikipedia article 的相关内容,(强调我的

C 编程语言(和许多衍生语言)中的struct 是一种复杂的数据类型声明,它定义了一个物理分组的变量列表,这些变量以一个名称放置在一块内存中,允许通过单个指针或返回相同地址的结构声明名称访问不同的变量。

在你的情况下,

struct student_record_node 
{
  struct class_record* record_;
  struct class_record_node* next_;
};

是用户定义类型struct student_record_node的声明,您可以通过说来创建该类型的变量

struct student_record_node stu_record;  //stu_record is the variable name

【讨论】:

  • struct 引入了一个结构说明符,而不是定义。严格来说,您没有定义struct,而是指定它。如果单独使用(struct { int i; };,您有一个声明。因此,任何struct 定义都将涉及定义struct 类型的对象。
【解决方案2】:

你有一个struct class_recordstruct class_record_node类型的指针

您误解了变量的结尾。

【讨论】:

  • 谢谢大家。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-17
  • 1970-01-01
  • 1970-01-01
  • 2013-04-01
  • 1970-01-01
  • 2013-07-12
相关资源
最近更新 更多