moderncprogramming.com/how-to-implement-private-variables-in-the-c-language/
1 Users
0 Comments
1 Highlights
1 Notes
Tags
Top Highlights
In the C programming language there is no keyword private. There are no classes and in a struct everything is public all the time. There is however the keyword static. When used within a function, static makes the variable save it’s content at a fixed memory address. When called the first time, the initialization value is set. When called again, the last saved value is used again. The second usage of static is the one we are after. When a variable (or function) is declared globally within a .c-File and given the keyword static, then the access to it is limited to the file. This way we can declare a private variable and/or private function.
Glasp is a social web highlighter that people can highlight and organize quotes and thoughts from the web, and access other like-minded people’s learning.