static functions are functions that are only visible to other functions in the same file (more precisely the same translation unit).

EDIT: For those who thought that the author of the questions meant a 'class method': As the question is tagged C he means a plain old C function. For (C++/Java/...) class methods, static means that this method can be called on the class itself, no instance of that class necessary.

Answer from Johannes Weiss on Stack Overflow
Top answer
1 of 11
899

static functions are functions that are only visible to other functions in the same file (more precisely the same translation unit).

EDIT: For those who thought that the author of the questions meant a 'class method': As the question is tagged C he means a plain old C function. For (C++/Java/...) class methods, static means that this method can be called on the class itself, no instance of that class necessary.

2 of 11
241

There is a big difference between static functions in C and static member functions in C++. In C, a static function is not visible outside of its translation unit, which is the object file it is compiled into. In other words, making a function static limits its scope. You can think of a static function as being "private" to its *.c file (although that is not strictly correct).

In C++, "static" can also apply to member functions and data members of classes. A static data member is also called a "class variable", while a non-static data member is an "instance variable". This is Smalltalk terminology. This means that there is only one copy of a static data member shared by all objects of a class, while each object has its own copy of a non-static data member. So a static data member is essentially a global variable, that is a member of a class.

Non-static member functions can access all data members of the class: static and non-static. Static member functions can only operate on the static data members.

One way to think about this is that in C++ static data members and static member functions do not belong to any object, but to the entire class.

🌐
GeeksforGeeks
geeksforgeeks.org › c language › what-are-static-functions-in-c
Static Functions in C - GeeksforGeeks
July 23, 2025 - The primary application of static function is to limit its scope to the translation unit where they are declared. This helps in achieving two things: Data hiding as we can hide the function from other translation units or files.
Discussions

static function in C - Stack Overflow
Nah, I'm confused with Python. A function inside a class is called a method in Python. ... Making a function static hides it from other translation units, which helps provide encapsulation. More on stackoverflow.com
🌐 stackoverflow.com
Have you ever used a static function?
The linker has to manage a huge database of symbols (conceptually) to make sure that any externally linked symbol is available to everything that asks for it. When your project gets huge, the database gets huger. If a symbol is not needed outside of a file, it should be static, because then it won't pollute what the linker has to go through. It also helps reduce the number of "whoops, I accidentally used this function name in two completely different and unrelated places" problems. I would also say do this for global variables (but unless you have a good reason, make sure the declaration is not in a header). More on reddit.com
🌐 r/C_Programming
13
1
March 28, 2022
Static Function Usage in C - Programming & Development - Spiceworks Community
Can we use static function in C? If yes, please let me what are those situations where I can use static function and what is its scope ? More on community.spiceworks.com
🌐 community.spiceworks.com
0
December 2, 2011
When do 'static functions' come into use? - Software Engineering Stack Exchange
Because file-scoped static functions ... use in C++, while replacing public static member with private non-static member just does not make much sense. Unfortunately OP does not seem to be responding. ... Assuming that you're using OOP, use static functions when they don't depend on any class ... More on softwareengineering.stackexchange.com
🌐 softwareengineering.stackexchange.com
People also ask

Can a static function return a pointer to a static variable?
Yes, a static function can return a pointer to a static variable because the static variable retains its value throughout the program's lifetime. Yes, a static function can return a pointer to a static variable because the static variable retains its value throughout the program's lifetime. Example: #include static int* get_static_var() { static int num = 42; // Static variable return #}int main() { int* ptr = get_static_var(); printf("Static variable value: %d\n", *ptr); // Dereferencing pointer return 0;} #include < stdio . h > static int * get_static_var ( ) { static int num = 42 ; //
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › static function in c
Static Function in C: Definition, Examples & Best Practices
Can a static function be recursive?
Yes, static functions can be recursive just like regular functions. The difference is that static functions are only accessible within the same file, which doesn't prevent them from calling themselves recursively. Example: #include static int factorial(int n) { if (n <= 1) return 1; return n * factorial(n - 1); // Recursive static function call}int main() { int num = 5; printf("Factorial of %d is: %d\n", num, factorial(num)); return 0;} #include < stdio . h > static int factorial ( int n ) { if ( n <= 1 ) return 1 ; return n * factorial ( n - 1 ) ; // Recursive static function call
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › static function in c
Static Function in C: Definition, Examples & Best Practices
Can a static function access static functions from other files?
No, a static function cannot access static functions from another file because static functions have internal linkage. They are only visible within the file they are defined in. No, a static function cannot access static functions from another file because static functions have internal linkage . They are only visible within the file they are defined in.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › static function in c
Static Function in C: Definition, Examples & Best Practices
🌐
Cppreference
en.cppreference.com › w › cpp › language › static.html
static members - cppreference.com
August 14, 2024 - The name of any static data member and static member function must be different from the name of the containing class. Static members of a class are not associated with the objects of the class: they are independent variables with static or thread(since C++11) storage duration or regular functions.
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › static function in c
Static Function in C: Definition, Examples & Best Practices
April 3, 2025 - Learn about the Static Function in C, its purpose, how it works with static variables, and real-world applications with practical examples!
🌐
Scaler
scaler.com › home › topics › what is a static function in c?
What is a Static Function in C? - Scaler Topics
June 11, 2024 - Static functions in C are functions that are restricted to the same file in which they are defined. The functions in C are by default global. If we want to limit the scope of the function, we use the keyword static before the function.
Find elsewhere
🌐
Reddit
reddit.com › r/c_programming › have you ever used a static function?
r/C_Programming on Reddit: Have you ever used a static function?
March 28, 2022 -

I understand that they're used to limit the scope of a function to that object file, but can't wrap my head around why anyone would want to do that?

static int foo(void) {
    ...
}

What's the purpose of these? The only thing I've found convincing is:

As usual, the smaller the scope, the better, so always declare functions static
if you can.

In C programming, files are often used to represent "classes", and static
functions represent "private" methods of the class.

A common C pattern is to pass a this
struct around as the first "method" argument, which is basically what C++ does under the hood.

The answer is from this SO post

🌐
Spiceworks
community.spiceworks.com › programming & development
Static Function Usage in C - Programming & Development - Spiceworks Community
December 2, 2011 - Can we use static function in C? If yes, please let me what are those situations where I can use static function and what is its scope ?
🌐
TutorialsPoint
tutorialspoint.com › static-functions-in-c
Static functions in C
A static function in C is a function that has a scope limited to its object file. This means the static function is only visible within the file where it is defined and cannot be accessed from other files.
🌐
Learn C++
learncpp.com › cpp-tutorial › static-member-functions
15.7 — Static member functions – Learn C++
September 18, 2007 - This class utilizes a static member variable to hold the value of the next ID to be assigned, and provides a static member function to return that ID and increment it. As noted in lesson 15.2 -- Classes and header files, member functions defined inside the class definition are implicitly inline.
🌐
Bogotobogo
bogotobogo.com › cplusplus › statics.php
C++ Tutorial: Static Variables and Static Class Members - 2020
There is only a single instance of each static data member for the entire class: A static data member : class variable A non-static data member : instance variable · Static member function: it can only access static member data, or other static member functions while non-static member functions can access all data members of the class: static and non-static.
🌐
Wikipedia
en.wikipedia.org › wiki › Static_(keyword)
static (keyword) - Wikipedia
1 week ago - C doesn't support block-scoped functions. Therefore, in C, the term "static variable" has two meanings which are easy to confuse: A variable with the same lifetime as the program, as described above (language-independent); or · (C-family-specific) A variable declared with storage class static.
🌐
GNU
gnu.org › software › c-intro-and-ref › manual › html_node › Static-Functions.html
Static Functions (GNU C Language Manual)
For instance, if one compilation module contains this code: ... then the code of that compilation module can call foo anywhere after the definition, but other compilation modules cannot refer to it at all. To call foo before its definition, it needs a forward declaration, which should use static since the function definition does.
🌐
SkillVertex
skillvertex.com › blog › static-functions-in-c
Static Functions In C
May 10, 2024 - This keeps the function file local, improving modularity and preventing naming conflicts in larger programs. Ans. Static functions and properties are part of the class or struct itself, not tied to instances.
🌐
Cplusplus
cplusplus.com › forum › beginner › 59831
static non-member functions - C++ Forum
I'm not meaning a member function, but rather a function present in the main cpp file. For example: what is the difference between declaring such a function as static instead to not to? I know how it works with member functions, but this is not a member of any class, is a simple function.
🌐
Quora
quora.com › When-do-we-use-static-functions-vs-normal-functions-in-C
When do we use static functions vs normal functions in C? - Quora
Answer (1 of 3): The short answer is you declare a function static when you don’t want it to be possible to call it from code in another source file. Now for the long answer. When you’re working on a big project, you are often writing functions that other people will call.
🌐
Tutorialspoint
tutorialspoint.com › cplusplus › cpp_static_members.htm
Static Members of a C++ Class
A static member function can be called even if no objects of the class exist and the static functions are accessed using only the class name and the scope resolution operator ::.
🌐
HCL GUVI
studytonight.com › forum › what-is-a-static-function-in-c
What is a “static” function in C?
May 15, 2021 - Enhance your coding skills with HCL GUVI's Practice Platforms—interactive, structured, and designed to help you master programming effortlessly.