C static Keyword
Example
The static
keyword allows a variable to keep its value after a function
ends:
int add(int myNumber) {
static int total = 0;
total +=
myNumber;
return total;
}
int main() {
printf("%d\n",
add(5));
printf("%d\n", add(2));
printf("%d\n", add(4));
printf("%d\n", add(9));
return 0;
}
Try
it Yourself »
Definition and Usage
The static
keyword allows a variable inside a function to keep its value
across multiple function calls.