Question about functions?

closed account (EApGNwbp)
For all programs with different functions do we always have to have the callback in the main function? I've heard some people say this but what would you guys suggest when writing a program? I am very confused with functions your tips would help me so much!
Nope. You can call a function from the main() function, from another function, from a member function, etc.

Here's a way to visualize functions.
Suppose our entire program is an airplane begin assembled by Boeing. We know that when Boeing is making a plane, they don't build every little piece themselves. Rather they have pieces assembled in factories (the engines, the landing wheels, etc) and those large pieces are shipped to Boeing to be assembled.

So! If our program is an airplane being built, a function is those large pieces. We build those large pieces at the beginning and then we can use them later on multiple times in different places.

In other words, we build our functions (which are just simple subroutines) and we can then use those functions throughout our program at different spots in the program.

Also, you can think of a classic example... the clear_screen() function (just a simple function that clears the screen). Obviously we will want to clear the screen multiple times, so instead of typing out the whole for loop for clearing the console every time, we can write a function to do it and then just call the function. This simplifies our process tremendously.

Hope this helps some.
Last edited on
Topic archived. No new replies allowed.