OneBite.Dev - Coding blog in a bite size

declare a global variable in C

Code snippet on how to declare a global variable in C

  int gVar;  // Declare an integer global variable

This code declares an integer global variable called ‘gVar’. The ‘int’ keyword is used to denote that this variable is of type integer. The ‘gVar’ label is used to refer to this global variable throughout our program. Global variables are variables that can be accessed by any function throughout the program, so they are usually declared at the beginning of the program. Once a global variable is declared, its value can be changed by any function in the program, so care must be taken when modifying global variables.

c