Complete the code to declare a global variable.
#include <stdio.h> [1] count = 10; int main() { printf("Count is %d\n", count); return 0; }
The keyword int declares the variable count as a global integer variable accessible throughout the file.
Complete the code to declare a local variable inside main.
#include <stdio.h> int main() { [1] number = 5; printf("Number is %d\n", number); return 0; }
The keyword int declares a local integer variable number inside the main function.
Fix the error in the code by choosing the correct keyword for the variable inside the function.
#include <stdio.h> int count = 20; int main() { [1] count = 10; printf("Count is %d\n", count); return 0; }
Declaring int count = 10; inside main creates a local variable that hides the global count. This is valid and fixes the error.
Fill both blanks to declare a static variable inside a function and initialize it.
#include <stdio.h> void func() { [1] int counter = [2]; counter++; printf("Counter: %d\n", counter); } int main() { func(); func(); return 0; }
Using static makes counter keep its value between calls. Initializing it to 0 starts counting from zero.
Fill all three blanks to create a function that modifies a global variable.
#include <stdio.h> [1] total = 0; void add(int value) { total [2]= value; } int main() { add([3]); printf("Total: %d\n", total); return 0; }
Declare total as a global int. Use += to add value to total. Call add(5) to add 5 to total.