When to choose global variable?

Programming, for all ages and all languages.
Post Reply
NOTNULL

When to choose global variable?

Post by NOTNULL »

Hello all,
Consider a linked list program. Which would be the best option to choose the "head" pointer? keeping it global and accessing over all the other functions or keeping it local and passing it to all the functions.

Thanks in advance.
zloba

Re:When to choose global variable?

Post by zloba »

depends on what you're trying to do, your program model.

if there is to be a single list (or several lists) which has a specific meaning, global to the program, then you make it global.

if there may be a number of lists used here and there for different purposes, then you pass those around as needed.
Post Reply