As a general rule, why is it a good idea to avoid the excessive use of global variables. Please answer in detail, better if in points.
As a general rule, why is it a good idea to avoid the excessive use of global variables. Please answer in detail, better if in points.
I can say from experience, debugging a lot of global variables is tricky.
In a project I was involved with, there were two global variables with similar names (two sub-states from the same struct). Because the state needs to be visible to all parts of the code (so one section didn't go into a state that shouldn't run when the other is in some state), use of local variables was not a preferred option.
A state from one variable was accidentally given to the other. Because the modification was made in another place of the program and because the names looked similar, it was very hard to find.
Fact - Beethoven wrote his first symphony in C
I think this sums it up pretty well: Global Variables Are Bad.
> Please answer in detail, better if in points.
So you can copy/paste directly into your homework answer?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
In case to avoid the probability of what salem said i will say only this:
Imagine a large program which uses global variables.It is extremely possible that manu variables are going to conflict with others, in case of same names...So you have to resolve which one is shadowing the others etc.. This does not only make it difficult from you, but extremely unreadable for the others.
For more,see what the above post says