0
0
Cprogramming~10 mins

Static storage class - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a static variable inside a function.

C
void func() {
    static int [1] = 0;
    [1]++;
    printf("%d\n", [1]);
}
Drag options to blanks, or click blank then click option'
Anum
Bcount
Cvalue
Dtemp
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-static variable which resets every function call.
Forgetting to use the same variable name in all places.
2fill in blank
medium

Complete the code to declare a static global variable.

C
[1] int counter = 0;

void increment() {
    counter++;
}
Drag options to blanks, or click blank then click option'
Aregister
Bextern
Cauto
Dstatic
Attempts:
3 left
💡 Hint
Common Mistakes
Using extern which declares an external variable.
Using auto or register which are for local variables.
3fill in blank
hard

Fix the error in the code by completing the declaration of a static variable inside a function.

C
void demo() {
    [1] int x = 5;
    x++;
    printf("%d\n", x);
}
Drag options to blanks, or click blank then click option'
Aauto
Bregister
Cstatic
Dextern
Attempts:
3 left
💡 Hint
Common Mistakes
Using auto or register which are for automatic variables.
Using extern which is for external linkage.
4fill in blank
hard

Fill both blanks to create a static variable inside a function and print its value.

C
void count_calls() {
    [1] int calls = 0;
    calls[2];
    printf("Calls: %d\n", calls);
}
Drag options to blanks, or click blank then click option'
Astatic
B++
C--
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-static variable which resets every call.
Using the wrong operator to change the variable.
5fill in blank
hard

Fill all three blanks to declare a static variable, increment it, and print its value.

C
void func() {
    [1] int num = 0;
    num[2];
    printf("Number: %d\n", [3]);
}
Drag options to blanks, or click blank then click option'
Astatic
B++
Cnum
D--
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to declare the variable as static.
Using the wrong variable name in the print statement.