void function

void is the type of function which doesn't need to return
then why is this program not working ?

#include <iostream>
using namespace std;
void addition(int a,int b);
{
int r;
r=a+b;
}
int main()
{
int z;
z=addition(5,4);
cout <<"the result is "<<z;
return 0;
}
Void doesn't return any value: here you are trying to store the returnvalue of the function into z, but the function doesn't have a returnvalue, and so it's not valid. addition() should be of type integer and return r.
can you please correct this program , void should be in there
Last edited on
No, do it yourself.
firedraco is right, you need to do it yourself. But a little hint: you'll need pointers.
And watch out for "extra" semicolons.
I would suggest using an integer return type because that function doesn't do a thing. The main function can not access the variable r.
The OP said he should use type void: this is probably an assigment to practize with pointers.
Globals work too.
Topic archived. No new replies allowed.