I know that using Global Variables in programming may create lots of problems in long term , like , Bugs , Lags and more . I am working on a program which has more than 5 functions which need to access global variables something like this.
int Name;
int Age;
int Weight;
String EyeColour;
void AddValues(int N, int A , int W , String EC){
Name = N;
Age = A;
Weight = W;
EyeColour = EC;
}
// All the functions below use those Global Variables
void function2(){
...
}
void function2(){
...
}
void function3(){
...
}
void function4(){
...
}
void function5(){
...
}
But according to this article
I should avoid using global variables to avoid future problems so I wrapped them up inside a struct. Like this.
struct Person{
int Name;
int Age;
int Weight;
String EyeColour;
}
Now my main question is, should I declare the structure variable globally? Will it avoid the problems which could be created by global variables ?
If I declare the struct variable globally will it be equivalent to declaring variables globally instead of the structure?
Or
Should I declare the structure variable inside all the functions instead of declaring globally?
So that all functions can work flawlessly without any global variable problems.