So i'm trying to figure out the difference between a void function and a int function what is the difference? Also i'm going to have a few questions about structures later :) Thanks in advanced.
functions yield a result which is of a specific type.
void means nothing.
so
1 2 3 4 5 6 7 8 9 10 11 12 13 14
int f1()
{
return 5; // return value must be same type as declared
}
float f2()
{
return 5.0f; // return value must be same type as declared
}
void f3()
{
// no return here because no return type.
}
int f1( int a, int b)
{
// Would return numbers from an equation such as
int x;
x = 0;
x = (a + b);
// To another function correct?
return x;
}
// whereas a void would be more for a text box? such as
void f2()
{
cout << "This is a void function";
}
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
void function CAN'T return any value, but it can do anything.
int/double/float/bool function MUST return value, and it can do anything.
the difference is CAN'T and MUST.
if you don't return any value in non void function, you will get error message.
and if you try to return value in void function, you will get error too