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

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
syntax - What does "static" mean in C? - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... I've seen the word static used in different places in C code; is this like a static function/class in C# (where the implementation is shared across objects)? More on stackoverflow.com
🌐 stackoverflow.com
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
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
People also ask

What is the difference between static and extern function in C?
A static function is local to its translation unit (source file), meaning it can only be accessed within the file where it is defined.An extern function is visible across multiple source files. The extern keyword tells the compiler that the function is defined elsewhere (in another file). A static function is local to its translation unit (source file), meaning it can only be accessed within the file where it is defined. A static function is local to its translation unit (source file), meaning it can only be accessed within the file where it is defined. An extern function is visible across mul
🌐
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 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
🌐
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.
🌐
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.
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › static function in c
Static Function in C: Definition, Examples & Best Practices
April 3, 2025 - While static function in C is helpful for restricting access and limiting visibility, overusing them can make your code harder to maintain. If every function is static, it might indicate a design flaw, especially in larger applications where ...
🌐
TutorialsPoint
tutorialspoint.com › static-functions-in-c
Static functions in C
Here's an example demonstrating a static function called within the same file − · #include <stdio.h> static void staticFunc(void) { printf("Inside the static function staticFunc()<br>"); } int main() { staticFunc(); return 0; } ... To understand the limited scope of static functions, consider this conceptual example.
Find elsewhere
🌐
w3resource
w3resource.com › c-programming-exercises › c-snippets › what-is-a-static-function-in-c.php
What is a static Function in C? Scope and usage explained
The output shows that publicFunction() is able to call staticFunction() within helper.c, but staticFunction() is not accessible in main.c. ... For Helper Functions: Use static for helper functions that should not be exposed outside their file. Internal Operations: If a function is only relevant to the implementation of other functions in the same file, it’s a good candidate for static.
🌐
Learn C
learn-c.org › en › Static
Static - Learn C - Free Interactive C Tutorial
If static is used however, we get ... are global in C. If we declare a function with static, the scope of that function is reduced to the file containing it....
🌐
GeeksforGeeks
geeksforgeeks.org › c language › static-variables-in-c
Static Variables in C - GeeksforGeeks
Explanation: In this program, fun() returns a pointer to the static local variable local_var, which retains its value even after the function exits. Unlike normal local variables, which are destroyed when function exits. As these variables are only initialized once and retain their value, they can be used to control the recursion in case of infinite recursive calls.
Published   July 23, 2025
Top answer
1 of 16
1943

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

  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.

(1) is the more foreign topic if you're a newbie, so here's an example:

#include <stdio.h>

void foo()
{
    int a = 10;
    static int sa = 10;
    
    a += 5;
    sa += 5;
    
    printf("a = %d, sa = %d\n", a, sa);
}


int main()
{
    int i;
    
    for (i = 0; i < 10; ++i)
        foo();
}

This prints:

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

This is useful for cases where a function needs to keep some state between invocations, and you don't want to use global variables. Beware, however, this feature should be used very sparingly - it makes your code not thread-safe and harder to understand.

(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.

See here and here for more details.

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

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, 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:

void func(int foo[static 42]);

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

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

2 of 16
296

There is one more use not covered here, and that is as part of an array type declaration as an argument to a function:

int someFunction(char arg[static 10])
{
    ...
}

In this context, this specifies that arguments passed to this function must be an array of type char with at least 10 elements in it. For more info see my question here.

🌐
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 }
🌐
Educative
educative.io › answers › what-are-static-functions-in-c
What are Static functions in C?
A function is defined as static by the use of static keyword with the function’s name. The use of a static function is restricted to its object file where it is declared. ... Functions are declared static to limit access.
🌐
Codecademy
codecademy.com › docs › static variables
C | Static Variables | Codecademy
April 28, 2025 - There are two main uses of the static keyword in C: to create variables with persistent values within functions, and to limit the visibility of variables or functions to a single file.
🌐
Quora
quora.com › What-is-the-static-function-in-C-and-how-is-it-used
What is the static function in C, and how is it used? - Quora
Answer (1 of 5): Hey, Here is the explanation- In C, functions are global by default. The “static” keyword before a function name makes it static. For example, below function fun() is static.
🌐
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. We can define a function static by using following syntax · static return_type function_name(arguments) { function_body; } Here is a function to find square root of a given number
🌐
SkillVertex
skillvertex.com › blog › static-functions-in-c
Static Functions In C
May 10, 2024 - This is in contrast to global functions, which are accessible from any part of a program that includes the function’s declaration. So, by adding the “static” keyword to a function in C, you limit its visibility to the file it’s defined in, making it file-local. This can be useful for encapsulating functions that are intended for use within a single source file and are not meant to be exposed to other parts of the program.