Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Global and Local scope
#1
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;
}
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)