Question about functions

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.
}
can u give an example??
Jaybob66 just gave three examples. What further examples do you want?

Last edited on
Thank you Jaybob66 So as an example if i was just doing a quick lets say

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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";

}


Do i have that correct for the most part?

((Fixed sorry about that))
Last edited on
Do i have that correct for the most part?

Yes.

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/
Fixed sorry about that :) thank you again.
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
Topic archived. No new replies allowed.