简体   繁体   English

在向量上返回C中的Void函数

[英]return of Void Function in C on a vector

#include <stdio.h>

#define N 5

void mult (int v[], int N, int g);

int main() {
    int i, v[N], x;
    for (i=0; i<N; i++){
        printf("Inserirt value in %d position: ", i+1);
        scanf("%d", &v[i]);
    }
    printf("Insert value to moltiply each vector value: ");
    scanf("%d", &x);
    mult(v,N,x);
    for (i=0; i<N; i++){
        printf("%d ", v[i]);
    }
    return 0;
}

void mult (int v[], int N, int g){
    int i;
    for (i=0; i<N; i++){
        v[i]=g*(v[i]);
    }
}

I don't know how it doesn't work, maybe there's a problem on void function, sorry for the stupid question, but I'm studying it at university and the teacher said to write this program using the void function without the return into the function declaration. 我不知道它是如何起作用的,也许有无效功能的问题,对不起这个愚蠢的问题,但是我正在大学学习它,老师说要用void函数写这个程序而不返回功能声明。 Thanx everybody. 大家好。

N is defined as a macro which gets replaced by the preprocessor before compiling the source code. N被定义为在编译源代码之前被预处理器替换的宏。

For instance, the prototype for the mult function will look to the compiler like the following: 例如, mult函数的原型将查看编译器,如下所示:

void mult (int v[], int 5, int g);

producing compile-time errors. 产生编译时错误。

Use a different name either for the macro or the parameter. 对宏或参数使用不同的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM