declare global variable in class c++ code example

Example 1: c++ variable globale

#include <iostream>

int global = 3; // Une variable globale

void ChangeGlobal()
{
   global = 5; // Référence à la variable globale à l'intérieur d'une fonction
}

int main()
{
   std::cout << global << '\n'; // Référence à la variable globale dans une autre fonction
   ChangeGlobal();
   std::cout << global << '\n';
   return 0;
}

Example 2: cpp global variable

int g_x; // global variable g_x

Tags:

Cpp Example