Skip to main content
Restore all links (using the Wayback Machine for the dead links)
Source Link

Quoting [Wikipedia][1]Wikipedia:

See here and here for more details.

And to answer your second question, it's not like in C#.

Additionally, in C, static can be used in array declarators to [specify minimum size of the array][1]specify minimum size of the array (non-function array declarators cannot use this keyword). Consider this declaration:

Quoting [Wikipedia][1]:

And to answer your second question, it's not like in C#.

Additionally, in C, static can be used in array declarators to [specify minimum size of the array][1] (non-function array declarators cannot use this keyword). Consider this declaration:

Quoting Wikipedia:

See here and here for more details.

And to answer your second question, it's not like in C#.

Additionally, in C, static can be used in array declarators to specify minimum size of the array (non-function array declarators cannot use this keyword). Consider this declaration:

Inline link; various copy-edit improvements
Source Link
Toby Speight
  • 32.3k
  • 58
  • 83
  • 118
  1. A static variable inside a function keeps its value between invocations.
  2. A static global variable or a function is "seen" only in the file in which it's declared in.
a = 15, sa = 15 a = 15, sa = 20 a = 15, sa = 25 a = 15, sa = 30 a = 15, sa = 35 a = 15, sa = 40 a = 15, sa = 45 a = 15, sa = 50 a = 15, sa = 55 a = 15, sa = 60 
a = 15, sa = 15 a = 15, sa = 20 a = 15, sa = 25 a = 15, sa = 30 a = 15, sa = 35 a = 15, sa = 40 a = 15, sa = 45 a = 15, sa = 50 a = 15, sa = 55 a = 15, sa = 60 

(2) Isis used widely as an "access control" feature. If you have a .c file implementing some functionality, it usually exposes only a few "public" functions to users. The rest of its functions should be made static, so that the user won't be able to access them. This is encapsulation, a good practice.

Quoting Wikipedia[Wikipedia][1]:

In the C programming language, staticstatic is used with global variables and functions to set their scope to the containing file. In local variables, staticstatic is used to store the variable in the statically allocated memory instead of the automatically allocated memory. While the language does not dictate the implementation of either type of memory, statically allocated memory is typically reserved in data segment of the program at compile time, while the automatically allocated memory is normally implemented as a transient call stack.

Additionally, in C, keyword static can be used in array declarators to specify[specify minimum size of the array.array][1] (Nonnon-function array declarators cannot use this keyword.). Consider this functiondeclaration:

Such aThe function can takefunc() takes an array of at least 42 elements.

Note that in C++, such usage does not support this use of the static keyword is not allowed.

cppreference.com covers this topic quite well: https://en.cppreference.com/w/c/language/array

  1. A static variable inside a function keeps its value between invocations.
  2. A static global variable or a function is "seen" only in the file it's declared in
a = 15, sa = 15 a = 15, sa = 20 a = 15, sa = 25 a = 15, sa = 30 a = 15, sa = 35 a = 15, sa = 40 a = 15, sa = 45 a = 15, sa = 50 a = 15, sa = 55 a = 15, sa = 60 

(2) Is used widely as an "access control" feature. If you have a .c file implementing some functionality, it usually exposes only a few "public" functions to users. The rest of its functions should be made static, so that the user won't be able to access them. This is encapsulation, a good practice.

Quoting Wikipedia:

In the C programming language, static is used with global variables and functions to set their scope to the containing file. In local variables, static is used to store the variable in the statically allocated memory instead of the automatically allocated memory. While the language does not dictate the implementation of either type of memory, statically allocated memory is typically reserved in data segment of the program at compile time, while the automatically allocated memory is normally implemented as a transient call stack.

Additionally, in C, keyword static can be used in array declarators to specify minimum size of the array. (Non-function array declarators cannot use this keyword.) Consider this function:

Such a function can take an array of at least 42 elements.

Note that in C++, such usage of the static keyword is not allowed.

cppreference.com covers this topic quite well: https://en.cppreference.com/w/c/language/array

  1. A static variable inside a function keeps its value between invocations.
  2. A static global variable or function is "seen" only in the file in which it's declared.
a = 15, sa = 15 a = 15, sa = 20 a = 15, sa = 25 a = 15, sa = 30 a = 15, sa = 35 a = 15, sa = 40 a = 15, sa = 45 a = 15, sa = 50 a = 15, sa = 55 a = 15, sa = 60 

(2) is used widely as an "access control" feature. If you have a .c file implementing some functionality, it usually exposes only a few "public" functions to users. The rest of its functions should be made static, so that the user won't be able to access them. This is encapsulation, a good practice.

Quoting [Wikipedia][1]:

In the C programming language, static is used with global variables and functions to set their scope to the containing file. In local variables, static is used to store the variable in the statically allocated memory instead of the automatically allocated memory. While the language does not dictate the implementation of either type of memory, statically allocated memory is typically reserved in data segment of the program at compile time, while the automatically allocated memory is normally implemented as a transient call stack.

Additionally, in C, static can be used in array declarators to [specify minimum size of the array][1] (non-function array declarators cannot use this keyword). Consider this declaration:

The function func() takes an array of at least 42 elements.

Note that C++ does not support this use of the static keyword.

Usually, you will see the static keyword in these places:

In C++, however, static is also used to define class attributes (shared between all objects of the same class) and methods. In C there are no classes, so this feature is irrelevant.


Additionally, in C, keyword static can be used in array declarators to specify minimum size of the array. (Non-function array declarators cannot use this keyword.) Consider this function:

void func(int foo[static 42]); 

Such a function can take an array of at least 42 elements.

Note that in C++, such usage of the static keyword is not allowed.

cppreference.com covers this topic quite well: https://en.cppreference.com/w/c/language/array

In C++, however, static is also used to define class attributes (shared between all objects of the same class) and methods. In C there are no classes, so this feature is irrelevant.

Usually, you will see the static keyword in these places:

In C++, however, static is also used to define class attributes (shared between all objects of the same class) and methods. In C there are no classes, so this feature is irrelevant.


Additionally, in C, keyword static can be used in array declarators to specify minimum size of the array. (Non-function array declarators cannot use this keyword.) Consider this function:

void func(int foo[static 42]); 

Such a function can take an array of at least 42 elements.

Note that in C++, such usage of the static keyword is not allowed.

cppreference.com covers this topic quite well: https://en.cppreference.com/w/c/language/array

Loading
added 52 characters in body
Source Link
Eli Bendersky
  • 276.2k
  • 92
  • 372
  • 427
Loading
added 211 characters in body
Source Link
Eli Bendersky
  • 276.2k
  • 92
  • 372
  • 427
Loading
added 537 characters in body
Source Link
Eli Bendersky
  • 276.2k
  • 92
  • 372
  • 427
Loading
Source Link
Eli Bendersky
  • 276.2k
  • 92
  • 372
  • 427
Loading