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??
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~~~~~~
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....