I am trying to create a void function in C programming that works with pointers. I have created the following functions that works with pointers:
#include <stdio.h>
int function_1(int *num1, int *num2) {
int *total;
*total = *num1 / *num2;
return *total;
}
int main(void) {
int numerator;
int denominator;
int finalAnswer;
printf("Numerator: ");
scanf("%d", &numerator);
printf("Denominator: ");
scanf("%d", &denominator);
finalAnswer = numerator / denominator;
printf("%d / %d = %d
", numerator,denominator,finalAnswer);
}
There is no problem with this program, but when I change the first line after
#include <stdio.h>
to this : void function_1(int *num1, int *num2) {
I get the following error when I try to compile my code :
prog1.c: In function ‘function_1’:
prog1.c:7:2: warning: ‘return’ with a value, in function returning void [enabled by default]
Sorry if I am doing something silly, but I have no idea what is wrong when I change int to void. I know void means nothing, but I want my code to return with void. Is it possible?
Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…