top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

where static variable initialised with 0 is stored?

+3 votes
81 views

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?

posted Jun 10, 2015 by Chirag Gangdev

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

It's not decided based on the initialized value of the static variable.

If a static/global variable is initialized then stored in initialized data segment .
and if static variable/global is not initialized then it will be stored in uninitialized data segment knows as BSS. So that it so extra care we need to take like before executing the code those variables present in BSS can be initialized with zero.

answer Jun 10, 2015 by Sachidananda Sahu
Similar Questions
+5 votes

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 ?

...