to what visibility do non global variables default

3 hours ago 1
Nature

Non-global variables, often referred to as local variables, by default have visibility limited to the block or function in which they are declared. This means they are only accessible within that specific function or code block and are not visible outside of it. This limited visibility is also called scope. Local variables typically have automatic duration, meaning they come into existence when the function is called and disappear when the function returns

. In contrast, variables declared outside of any function are global variables and have a broader visibility-they are potentially visible anywhere within the program unless explicitly restricted. Global variables usually have static duration, persisting for the entire runtime of the program

. To summarize:

  • Non-global (local) variables : Default visibility is limited to the function or block where they are declared (local scope).
  • Global variables : Default visibility is program-wide unless restricted by keywords like static in C, which limits visibility to the source file

Thus, non-global variables default to having visibility only within their defining function or block.