Why the use of Global Variables discouraged? | Sololearn: Learn to code for FREE!

+1

Why the use of Global Variables discouraged?

I submitted a program as an assignment in my Data Structures Course, the program was correct but I was not given full score and the teacher said that the reason of deduction of marks is due to usage of Global Variables in my program.

6/2/2019 10:00:26 AM

S Shashank

2 Answers

New Answer

+6

Coder San 1. Accidental modification by function since they are accessible to all 2. Consume memory - since they remain in memory throughout the lifetime of program. 3. By defailt have external linkage, which implies they visible across all translation units, and can cause name conflict.

+3

Because global variables are accessible from entire program and can be changed easily this may cause bugs..... Maybe I am wrong but I thik that is the reason