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 - Let's consider a C source file src.c that have a function calc() that should be available to all translation unit. But this function internally calls another function sum() to get the results. We need to hide the sum from other files. To do that, we can declare it as a static.
Discussions

When do you use static functions?
Static functions exist to restrict access to certain functions and to prevent collisions in the namespace. A static function should be declared at the top of the .c file and only referenced by the other functions in that .c file. The .h file should contain the functions that will be accessible to other files which include that .h file. In general, having a functions.h/functions.c file is kinda weird unless your program is very small. Normally, you would separate function groups by their specific interest. Most of the time, this is pretty obvious, but not always. More on reddit.com
๐ŸŒ r/C_Programming
36
49
April 7, 2024
Reasons to use Static functions and variables in C - Stack Overflow
I wonder about the use of the static keyword as scope limiting for variables in a file, in C. The standard way to build a C program as I see it is to: have a bunch of c files defining functions and More on stackoverflow.com
๐ŸŒ stackoverflow.com
programming languages - False friends? Keyword "static" in C compared to C++, C# and Java - Software Engineering Stack Exchange
Remember that as a language designer, ... be source-compatible with C, as in C++, and the static keyword already existed, so they couldn't break any C programs trying to compile as C++ by re-using it. Edit: I knew there was a third. C has function-level static variables... More on softwareengineering.stackexchange.com
๐ŸŒ softwareengineering.stackexchange.com
c - Static vs. non-static? (with non-OOP functions) - Software Engineering Stack Exchange
But what effect does this actually have with plain C? In my own projects, I've never had an occasion where the static keyword was actually needed. (Although a so-called expert programmer would probably have given me the advice, "This function should be declared static" and I would probably ... More on softwareengineering.stackexchange.com
๐ŸŒ softwareengineering.stackexchange.com
July 16, 2014
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 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
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
๐ŸŒ
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.
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ what-are-static-functions-in-c
What are Static functions in C?
C functions are global by default. A function is defined as static by the use of static keyword with the functionโ€™s name.
๐ŸŒ
Upgrad
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ static function in c
Static Function in C: Definition, Examples & Best Practices
April 3, 2025 - A static function in C is a function that is restricted to the file in which it is defined. When you declare a function as static, it has internal linkage, meaning the function can only be accessed from within the same translation unit (source ...
Find elsewhere
๐ŸŒ
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.
๐ŸŒ
IncludeHelp
includehelp.com โ€บ c โ€บ static-functions-in-c-language.aspx
Static functions in C Language
The static functions are those functions which are callable in the same file where they define.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ static-functions-in-c
Static functions in C
June 26, 2020 - Python TechnologiesDatabasesComputer ... Tutorials View All Categories ... A static function in C is a function that has a scope that is limited to its object file....
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ static-variables-in-c
Static Variables in C - GeeksforGeeks
In C programming, a static variable is declared using static keyword and have the property of retaining their value between multiple function calls. It is initialized only once and is not destroyed when the function returns a value.
Published ย  July 23, 2025
๐ŸŒ
ShareTechnote
sharetechnote.com โ€บ html โ€บ C_static.html
C/C++ | ShareTechnote
You sould see the static keyword quite frequently used, but you may get confused sometimes since the meaning of the keywords would change depending on the context. Especially the meaning get different a lot depending on whether it is used with a variable or function ยท The static keyword in ...
๐ŸŒ
Quora
quora.com โ€บ What-does-static-before-a-function-declaration-in-C-mean
What does 'static' before a function declaration in C mean? - Quora
Answer (1 of 5): Short Answer: It means the function name is only visible and callable in the file being compiled currently. Other files compiled separately will not see the function name or be able to call it.
๐ŸŒ
Sanfoundry
sanfoundry.com โ€บ c-tutorials-formal-parameters-function-declared-static
Static Function Parameters in C - Sanfoundry
May 14, 2025 - In file2.c, when we try to call it, the linker gives an error because the function isnโ€™t visible outside file1.c. This keeps functions safe and hidden when needed. ... Letโ€™s compare static functions and static variables declared inside functions.
๐ŸŒ
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 ?
๐ŸŒ
Exercism
exercism.org โ€บ tracks โ€บ c โ€บ concepts โ€บ static-functions
Static Functions in C on Exercism
// file scope, internal linkage // can only be called from within this file static void some_function() { // code snipped } // file scope, external linkage by default // can be called from any other file in the project int main() { // code snipped }
๐ŸŒ
Learn C
learn-c.org โ€บ en โ€บ Static
Static - Learn C - Free Interactive C Tutorial
If we declare a function with static, the scope of that function is reduced to the file containing it. ... While static variables have scope over the file containing them making them accessible only inside a given file, global variables can ...