07-25-2023, 11:35 AM
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;
}
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
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos