(All of this is for Langage C++)
Hi, you can use const and static keywords in few cases, for exemple :
Const
First, used to say that the variable cannot be modified.
int main() { const int toto[4] = {0, 1, 2, 3}; return (0); }
// We cannot modify toto after it declaration, why is it usefull? It keeps the state of your program design
Second, used to say that a method do not modify the object state.
class toto { int i; public: int geti() const; }
// All getter in CPP use it. Why is it usefull? Developper who use the class know that he do not modify the object state
Third, used to say that the parameter pass to a function isn't modify by the function.
int function(const std::string &str) { // function cannot modify the object string pass in parameter }
Static
First, used to say that a implemented function is know only inner a single file.
static int fct() { return (0); }
// You can ony call function fct() if you are inner the file who it is implemented
Second, used to say that a argument or method is common to all object of the same class.
class toto { public : static int getLol(); };
// Every object totoObj1, totoObj2 ... will call same function
Third and the last one, used to say that a variable do not change state between multiple call of the same function where it is declared
void fct() { static i = 0; std::cout << ++i << std::endl; }
// This function are going to print 1 then 2 then 3 ...
If you have any questions, you are welcome :)