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.
When to choose global variable?
Re:When to choose global variable?
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.
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.