top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Exactly what static variable means? Can you declare static variables within the header file?

+5 votes
526 views

You can find three principal uses for the static. This is a good way how to start your answer to this question. Let’s look at the three principal uses:

  1. Firstly, when you declare inside of a function: This retains the value between function calls

  2. Secondly, when it is declared for the function name: By default function is extern..therefore it will be visible out of different files if the function declaration is set as static..it will be invisible for outer files

  3. And lastly, static for global parameters: By default you can use global variables from outside files When it’s static global..this variable will be limited to within the file.

is this right ?

posted Jan 10, 2014 by Sandeep

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button
I wrote an article sometime back looks that it can answer all of your question.
http://tech.queryhome.com/25882/static-variables-in-c

Similar Questions
+3 votes

As per my understanding uninitialized static variable is stored in BSS and initialized static variable is stored in DS, then what about the variable which is initialized with 0 ? where it will be stored BSS/DS?

+5 votes

What would be the drawback if we define a static variable in the header file?

...