Create a global variable 'count' with the value 10. Create a local variable 'count' in the function with the value 5. Show the difference by printing both values ββinside and outside the function.
Official Solution
#include <stdio.h>
int count = 10; // Global variable
void showCount() {
int count = 5; // Local variable (shadows global)
printf("Inside function:n");
printf("Local count = %dn", count);
printf("Global count = %dn", ::count); // β Not allowed in C
}
int main() {
printf("Outside function (in main):n");
printf("Global count = %dnn", count);
showCount();
printf("nOutside function again (in main):n");
printf("Global count = %dn", count);
return 0;
}
No comments yet. Start the discussion!