Module 4 Quiz Question 2 says to call printIt from the main...

And I filled this in and it says it's correct... void printIt() { cout << "I love C++" << endl; } int main() { printIt(); return 0; } Now obviously I'm not done the course yet but I'm still curious... If you're meant to use void when you don't know the data type yet, why did they use void instead of char and also, why is main declared to be working with Integers if they're actually strings? TL;DR: Why does "int main" work when I'm printing non-integers?

12/25/2017 6:32:06 PM

Cael Collum

2 Answers

New Answer


There are two functions: main and print print just output a string and returns nothing, hence the return type is void main calls print and returns 0 if nothing goes wrong, hence it is an int. It is standard practice for main programs to return 0 if nothing goes wrong, but not always required. It is sort of like you asking someone to help do something for you, wouldn’t it be nice if you got a confirmation, when that task is done, opposed to checking it yourself?


Yes, this clears it up, it's an integer because the main is only concerned about whether or not it works (1 or 0), unrelated to the data type of the function being called within... Thank you!