Complete the code to declare a variable with automatic storage class.
void function() {
[1] int x = 10;
}static instead of auto inside functions.The auto keyword declares a variable with automatic storage, which is the default inside functions.
Complete the code to declare a variable with static storage class inside a function.
void counter() {
[1] int count = 0;
count++;
printf("%d", count);
}auto which resets the variable each call.The static keyword inside a function makes the variable keep its value between calls.
Fix the error in the code by choosing the correct storage class for a global variable.
[1] int global_var = 5; void func() { printf("%d", global_var); }
extern which declares a variable defined elsewhere.Using static for a global variable limits its scope to the file, which is often needed to avoid conflicts.
Fill both blanks to declare an external variable and use it in another file.
// file1.c [1] int shared_var = 100; // file2.c [2] int shared_var; void print_var() { printf("%d", shared_var); }
static in both files which hides the variable.In file1.c, static limits the variable to that file, so it should be removed to share it. The correct is to declare normally (no static) in file1.c and extern in file2.c to access it.
Fill all three blanks to declare a register variable, use it in a loop, and print its value.
void loop() {
[1] int i;
for (i = 0; i [2] 5; i++) {
printf("%d ", i);
}
printf("\nValue of i: %d", [3]);
}static inside the loop which changes variable lifetime.register suggests storing the variable in a CPU register for faster access. The loop runs while i < 5, and printing i shows its final value.