STATIC CONST - UtilityAcc/C-Notes GitHub Wiki

STATIC keyvord allow variable to save its value betwenn function calls, in recursions for example. STATIC INITS WITH ZERO VALUE `#include<stdio.h>

int runner()

{

int count = 0;
count++;
return count;

}

int main()

{

printf("%d ", runner());
printf("%d ", runner());
return 0;

}

` RETURNS 1 1 because count set to zero in every func call

` #include<stdio.h>

int runner()

{

static int count = 0;

count++;

return count;

}

int main()

{

printf("%d ", runner());
printf("%d ", runner());
return 0;

}

` RETURNS 1 2 BECAUS WITH STATIC CHANGED VALUE OF COUNT SAVES BETVEEn FUNC CALLS

STATIC FUNCTIONS By default, functions are global in C. If we declare a function with static, the scope of that function is reduced to the file containing it. Same for global variables - if use static they become visible only for current dile

CONST VAR WITH #DEFINE, replacement on stage of preprocessor

CONSTANT - READ ONLY VAR!!!

LINKS https://www.learn-c.org/en/Static https://www.geeksforgeeks.org/static-variables-in-c/ https://www.geeksforgeeks.org/const-qualifier-in-c/ https://www.tutorialspoint.com/declare-variable-as-constant-in-c

⚠️ **GitHub.com Fallback** ⚠️