If I have global variables, do I need to put them as a parameter of the function and will their value be changed by any function to be used by another function with using return?
If I have global variables, do I need to put them as a parameter of the function and will their value be changed by any function to be used by another function with using return?
Global variables are changable within the program (and they can be had with extern by other files in your project) so it is unnecessary to pass them in functions. You also don't return anything global.
Good just as I thought, and it doesn't matter now because I found my mistake and realised that I was right about global variables afterall.
What is so bad about using them? As most books seem to shy away from them.
It's all about design. If you find yourself passing the exact same structure or something to a lot of functions, or you need to have access to something accross lots of files, then it probably deserves to be global and you have a decision to make. But that's it.
The problem with global variables is that they can be modified globally, by any function anywhere in your program. This can create debugging nightmares in larger projects and is one major reason for projects being completely scrapped. This is why they are highly advised against using.
If they declared as const global variables the problem goes away, however. But you really wouldn't call them variables anymore, they'd be called global constants, which I think are O.K.