Static Local Variables | C Programming Tutorial

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Straight to the point and easy to understand videos. Earned a sub

flirtyemy
Автор

Very helpfull presentation, also a time stamp maybe added as per time frame in @5:12

fifaham
Автор

Is there any way to retrieve the current value of the static variable? In Effective C by Robert Seacord, one of the exercises is to "Add a retrieve function to the counting example form Listing 2-6 to retrieve the current value of the counter".
Listing 2-6 is just an increment function with a static variable btw:
void increment(void) {
static unsigned int counter = 0;
counter++;
printf("%d ", counter);
}

How could I add a function to retrieve the value if the scope is limited to the increment function? Wouldn't returning an int from increment() be the only way? (But if you did that, you wouldn't be able to retrieve the current value without incrementing it).

bsykesbeats
Автор

Why not declare calls as a global variable before int main (void) and calls++ later on in the code. Would that cause problems?

qneqne