Void PrintIntro () curiosity

Hi there.

As a beginner in C++ and programming, I can understand why we use the void command.
What I didn’t totally understand was on how do we know for the first time that we need to use it on this case.

Can someone clarify a beginner on this?

Best Regards

Because you don’t intend to give anything back to whatever called that function, as it just prints to the console.

1 Like

Hello dmesantos.

“void” is not a “command” in this case.
It is the type of the variable the function returns.
Every time you declare a function in c++, you have to specify what it takes (input) and what it returns (output).
Strictly speaking the function is: void PrintIntro(void)

Here is a link, which describes functions very well.
http://www.cplusplus.com/doc/tutorial/functions/
If you scroll a bit down, you will find the section “Functions with no type. The use of void”.
But I recommend to read all the text, then you will understand “functions”.

Hope that helps & happy coding.

Chris

2 Likes

Thanks Dan and Chris for the replies.

It really helps me to understand this.

Best Regards

Privacy & Terms