questions about void and its parameters

hi. i'm a total newbie in C++. so far, till now i'm confused about the function of void and its parameter. can somebody teach me how does it actually function??
....eventhough i'm still not very clear about its usage~~~~but anyway~~~thanks~~~~~~~~~
You have to be more clear on your question.

oo ok~~~~~
..... actually how to use void~~~~~
why does is needed to be separated from the main function~~~~
that's the thing i'm confusing about~~~~~~
What's with all the tildes?

why does is needed to be separated from the main function
I don't get this question. void is just a type (well, the absence of a type). What do you mean "separated from main()"?
......it's something like.....


void printblank(int blank);
int main()
{
int x;
cout << "input the number of blanks: ";
cin >> x;
printblank(x);
}

void printblank(int blank)
{
for (int i=1; i<=blank; i++)
cout << " " ;
cout << "hello\n" ;
}


why does the void printblank(int blank) needed to be separated from int main()??
Could you give an example of how it would look like if it didn't "need to be separated"?
.......no`~~~~~ i also dont really understand the function of void~~~~~
The code above has two functions -- main() and printblank().

main() takes no parameters and returns an int.

printblank() takes an integer as parameter and returns nothing (void).

main() calls printblank() and therefore printblank() must be declared before the usage in main(),
hence the void printblank(int blank); line immediately before int main().

The programmer of the code arbitrarily decided that s/he would create a separate function into which to place the output of leading spaces followed by "hello". There is no need to do that from a technical standpoint; the program could have worked just as well had main looked like

1
2
3
4
5
6
7
8
9
int main()
{
    int x;
    cout << "input the number of blanks: ";
    cin >> x;
    for (int i=1; i<=x; i++)
        cout << " ";
    cout << "hello\n";
}


I hope I covered all the possible meanings your question might have had....
oo i see~~~~~
now i got it~~~~~~
thanks ya~~~~~jsmith~~~~~
Topic archived. No new replies allowed.