小编pea*_*per的帖子

使用返回0;in void 函数是否可能?

我最近在 code::blocks 中使用 C 编程向我的导师提交了一个大数乘法和除法项目。在代码中间,我错误地使用了 return 0; 在空函数中:

void division_function (char str1[MAX_STR_LEN], char str2[MAX_STR_LEN])
{
    int len1 = strlen(str1);
    int len2 = strlen(str2);
    int num1[len1];
    int num2[len2];

    // In case the second number has more digits:
    if (len2 > len1)
    {
        printf("\nResult of division = 0");
        printf("\nRemainder = %s ", str1);
        return 0 ;
    }
    //rest of the code
Run Code Online (Sandbox Code Playgroud)

无论如何,在提交后,讲师给我发邮件说,由于使用了 void 函数中的 return a value ,代码失败了!我知道我应该使用 (return;) 而不是 (return 0;) 因为 void 函数不返回任何内容!我的问题是为什么我的控制台中没有出现任何错误!我只是测试了这段代码:

#include <stdio.h>
#include <stdlib.h>
void function (); …
Run Code Online (Sandbox Code Playgroud)

c

2
推荐指数
2
解决办法
3662
查看次数

标签 统计

c ×1