 Here's a program with functions to calculate three types of averages. The arithmetic mean, the geometric mean, and the seldom used, but very cool named, harmonic mean. The main program sets two variables, calculates the average, and prints the numbers on the average for all three of the functions. When we run it, it works exactly as intended. When many beginning programmers learn about functions, call-by-values, parameters, and local variables, these concepts are new and, to be honest, a bit confusing. Then they learn about global variables, and they think, hey, I can get rid of the parameters and return statements and make everything global. There, now I don't have to deal with all that confusing stuff. Here's the code using globals. We set the globals, here are our functions that all set the global result, and here we set the global variables, call each of the functions, and then print the numbers and the result. Let's see what happens when we run this program. This time everything is great until we get to the harmonic mean, and find out that our 5.5 and 4.0 have been changed. That's because here, in the harmonic mean function, we modified x and modified y, the global variables. This wasn't a problem in the original code, because we were modifying x and y, which were the local parameters, which left the original values of x and y for main totally untouched. There's another advantage of parameters and local variables. I can give these functions to anyone else to use, and I don't have to worry if they have variables of their own named x and y. In this example, the x and y in main can't and won't interfere with my parameters x and y in the functions. But with global variables, everyone else has to be careful to name their variables so they won't collide with my globals. Modifying global variables is an invitation to bring bugs into your program. Is it ever okay to use global variables? Yes, if they are constants. For example, a constant might be referenced in several different places in a program, and it makes sense to have it globally available. Or you might have an array that you don't want to reallocate every time you make a function call. Because they are constants, nobody can accidentally modify these globals. In summary, prefer parameters and local variables over global variables. Global constants can be very useful. If you absolutely must have modifiable global variables, be very careful.