c - 结构函数中的 '*'是什么?

标签 c struct syntax

struct Node *addToEmpty(struct Node *last, int data) 
{ 
  // This function is only for empty list 
  if (last != NULL) 
    return last; 

  // Creating a node dynamically. 
  struct Node *temp =  
       (struct Node*)malloc(sizeof(struct Node)); 

  // Assigning the data. 
  temp -> data = data; 
  last = temp; 

  // Creating the link. 
  last -> next = last; 

  return last; 
} 

struct Node *addBegin(struct Node *last, int data) 
{ 
  if (last == NULL) 
      return addToEmpty(last, data); 

  struct Node *temp =  
        (struct Node *)malloc(sizeof(struct Node)); 

  temp -> data = data; 
  temp -> next = last -> next; 
  last -> next = temp; 

  return last; 
} 

我想知道为什么使用“*addToEmpty”而不是“addToEmpty”。

结构体中的“*”是什么意思?

我知道这是基本问题。但我找不到答案。

如果你回答我的问题,我今天会很充实

附注这是 C++ 代码。

最佳答案

这是 C(++) 的 A 和 B [双关语]。

在此函数中,您将返回指向节点结构的指针...

您要求我们教您指针的基础知识。看看https://en.cppreference.com/w/cpp/language/pointer或者谷歌“在 C++ 中使用指针”,所有内容都会得到解释。

关于c - 结构函数中的 '*'是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58910186/

相关文章:

Java 相当于 Python 的 struct.pack?

ios - 在结构中传递法线

c - 为什么编译器会发出 : warning: assignment makes integer from pointer without a cast

haskell - Haskell 中的多个语句

c++ - 什么是远帕斯卡?

c++ - 函数原型(prototype)中的 "..."

字符数组比较问题

c execv通过函数传递参数

c - 如何使用 read() 系统调用将用户输入编写到程序中?

c - 如何检测 C 中的一个或多个键的笔划?