QP School
Global and Local scope - Printable Version

+- QP School (https://qomplainerzschool.lima-city.de)
+-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3)
+--- Forum: C 18 Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=32)
+--- Thread: Global and Local scope (/showthread.php?tid=5086)



Global and Local scope - Qomplainerz - 07-25-2023

Variables declared outside any function have global scope and can be accessed throughout the program. Variables declared inside a function have local scope and can only be accessed within that function.

int global_var = 10; // Global variable

void my_function() {
    int local_var = 5; // Local variable
    printf("Global variable: %d\n", global_var);
    printf("Local variable: %d\n", local_var);
}

int main() {
    my_function();
    return 0;
}