Printintro confusion

Why do we need the void PrintIntro(); in the top? What would happen if we were to omit that from the code? Would it still work?

It would not work unless, like in the lecture, you leave the whole function with the body on top but for neatness we don’t do that.

I’m not an expert but my possible explanations is that putting the name of the function on top acts like a header or precursor to what is about to come.

My other explanation is that the compiler reads code from top line down. Hence why you see the statements you wrote first executed first and so on and so forth. Without the function on top; the compiler would read the code from the top line and go down and see the function being called on main(), but the compiler wouldn’t know what it does and produce errors. With the function on top the compiler calls the functions your about to use first so that when they are actually called to be used it knows where to look and what it does. Hope this helps somewhat.

Privacy & Terms