user-0 提问: 脑袋都想破了，这也太难了....

回复:
user: user-0
content: 引用 4 楼 暁暁暁 的回复：你写成 return 0会出错是因为你的函数是void可是main函数也是void类型的，它却可以return 0，为什么？

user: user-0
content: 引用 5 楼 自信男孩 的回复：#include <stdio.h> #include <stdlib.h>  struct Node {     int value;     struct Node *next; };  void insertNode(struct Node **head, int value) {     struct Node *previous;     struct Node *current;     //struct Node *new;     struct Node *new_node;      current = *head;     previous = NULL;      while (current != NULL && current->value < value)     {         previous = current;         current = current->next;      }      new_node = (struct Node *)malloc(sizeof(struct Node));     if (new_node == NULL)     {         printf("内存分配失败！\n");         exit(1);     }      new_node->value = value;     new_node->next = current;      if (previous == NULL)     {         *head = new_node;     }     else     {         previous->next = new_node;     } }  void printNode(struct Node *head) {     struct Node *current;      current = head;     while (current != NULL)     {         printf("%d ", current->value);         current = current->next;     }      putchar('\n'); }  void deleteNode(struct Node **head, int value) {     struct Node *previous;     struct Node *current;      current = *head;     previous = NULL;      while (current != NULL && current->value != value)     {         previous = current;         current = current->next;     }      if (current == NULL)     {         printf("找不到匹配的节点！\n");         return ;    //为什么这里写成return 0会出错，写成return不会出错？这里的return有什么用？     }     else     {         if (previous == NULL)         {             *head = current->next;         }         else         {             previous->next = current->next;         }          free(current);     } } int main() {     struct Node *head = NULL;     int input;      printf("开始测试插入整数...\n");     while (1)     {         printf("请输入一个整数（输入-1表示结束）：");         scanf("%d", &input);         if (input == -1)         {             break;         }         insertNode(&head, input);         printNode(head);     }      printf("开始测试删除整数...\n");     while (1)     {         printf("请输入一个整数（输入-1表示结束）：");         scanf("%d", &input);         if (input == -1)         {             break;         }         deleteNode(&head, input);         printNode(head);     }      return 0; } 供参考～  函数返回值是值函数定义的数据类型，如果没有返回值，即定义的是void也是可以使用return的，只是return什么也不返回，直接跟分号。 return是退出函数并返回对应类型的数据。那为什么void类型的main函数可以用return返回零？零不是int类型的吗？

user: user-1
content: #include <stdio.h> #include <stdlib.h>  struct Node {     int value;     struct Node *next; };  void insertNode(struct Node **head, int value) {     struct Node *previous;     struct Node *current;     //struct Node *new;     struct Node *new_node;      current = *head;     previous = NULL;      while (current != NULL && current->value < value)     {         previous = current;         current = current->next;      }      new_node = (struct Node *)malloc(sizeof(struct Node));     if (new_node == NULL)     {         printf("内存分配失败！\n");         exit(1);     }      new_node->value = value;     new_node->next = current;      if (previous == NULL)     {         *head = new_node;     }     else     {         previous->next = new_node;     } }  void printNode(struct Node *head) {     struct Node *current;      current = head;     while (current != NULL)     {         printf("%d ", current->value);         current = current->next;     }      putchar('\n'); }  void deleteNode(struct Node **head, int value) {     struct Node *previous;     struct Node *current;      current = *head;     previous = NULL;      while (current != NULL && current->value != value)     {         previous = current;         current = current->next;     }      if (current == NULL)     {         printf("找不到匹配的节点！\n");         return ;    //为什么这里写成return 0会出错，写成return不会出错？这里的return有什么用？     }     else     {         if (previous == NULL)         {             *head = current->next;         }         else         {             previous->next = current->next;         }          free(current);     } } int main() {     struct Node *head = NULL;     int input;      printf("开始测试插入整数...\n");     while (1)     {         printf("请输入一个整数（输入-1表示结束）：");         scanf("%d", &input);         if (input == -1)         {             break;         }         insertNode(&head, input);         printNode(head);     }      printf("开始测试删除整数...\n");     while (1)     {         printf("请输入一个整数（输入-1表示结束）：");         scanf("%d", &input);         if (input == -1)         {             break;         }         deleteNode(&head, input);         printNode(head);     }      return 0; } 供参考～  函数返回值是值函数定义的数据类型，如果没有返回值，即定义的是void也是可以使用return的，只是return什么也不返回，直接跟分号。 return是退出函数并返回对应类型的数据。

user: user-2
content: 你写成 return 0会出错是因为你的函数是void

user: user-2
content: 引用 2 楼 weixin_45906870 的回复:引用 1 楼 user-3 的回复：因为这个函数没有返回值那这个return是结束这个函数的意思吗 对的，return就是结束本函数的意思，同时返回一个值。

user: user-0
content: 引用 1 楼 user-3 的回复：因为这个函数没有返回值那这个return是结束这个函数的意思吗

user: user-3
content: 因为这个函数没有返回值