my code

Jefferson Jose Torres Munoz

Static key word, static numbers to work with functions
by Jefferson Jose Torres Munoz

* Static Keyword in C     (Where is the static word in the function?)
1.-    Inside a function: retains its value between calls(lifetime)
      i   Static local variables

2.-    At the function level: visible only in this file (scope)
      i) Static global variables (only accesible to elements inside the C file)
      ii) Static functions     (limited to the C file, not form other sites)

Owner:  Hacker CS

Snippet options

Download: Download snippet as static-key-word-static-numbers-to-work-with-functions.c.
Copy snippet: For this you need a free my code account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

#include <stdio.h>
#include <stdlib.h>

static int x;                       //Static global variable, means "x" cannot be accesed form outside a C file

static                              // The word "statics saves the value to use it in the fucntion eventually"
void print_num(void)    {           //Static function
    static int y = 0;               //Static local variable
    printf("%d\n", y);              //Since it is a statics, the "y" will be retained to increment 1 by one, it is kind of stored in somewhere to be recalled form the previous call
    y = y +1;

int main(void)  {
    return 0;

Create a free my code account now.

my code is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.