how to define global array in c++ in a scope

#include <iostream>

// Step 1: Declare the global array
extern int globalArray[5];

// Step 2: Define the global array in a specific source file (e.g., main.cpp)
int globalArray[5] = {1, 2, 3, 4, 5};

int main() {
    // Step 3: Access the global array in the desired scope (e.g., main function)
    for (int i = 0; i < 5; ++i) {
        std::cout << "Element " << i << ": " << globalArray[i] << std::endl;
    }

    return 0;
}