global variables? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

global variables?

I have a program which I need it to constantly read a variable that can be used in all user defined functions. I understand that all variables are voided but is there a method to declare a global variable?

24th Jul 2016, 3:08 AM
Gary Jayz
Gary Jayz - avatar
2 Answers
0
Declare the variables you want to make it public before main function.... Using public Example #include <iostream> Using namespace std; public int age=5; public string name = "myName" ; main()
24th Jul 2016, 6:47 AM
Star Sign
Star Sign - avatar
0
Try to avoid them as they are considered to be bad practice. Might lead to slow start and close time of application.
26th Jul 2016, 3:10 AM
Stefan
Stefan - avatar