Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6704491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:17:41+00:00 2026-05-26T07:17:41+00:00

I have a choice to between declaring a variable static or global. I want

  • 0

I have a choice to between declaring a variable static or global.

I want to use the variable in one function to maintain counter.

for example

void count()
{
   static int a=0;
   for(i=0;i<7;i++)
   {
      a++;
   }

}

My other choice is to declare the variable a as global.
I will only use it in this function count().

Which way is the safest solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:17:42+00:00Added an answer on May 26, 2026 at 7:17 am

    It matters only at compile and link-time. A static local variable should be stored and initialised in exactly the same way as a global one.

    Declaring a local static variable only affects its visibility at the language level, making it visible only in the enclosing function, though with a global lifetime.

    A global variable (or any object in general) not marked static has external linkage and the linker will consider the symbol when merging each of the object files.

    A global variable marked static only has internal linkage within the current translation unit, and the linker will not see such a symbol when merging the individual translation units.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does one necessarily have to make a strict choice between using annotations and hibernate
I'm updating my code generator and have a choice between implementing a method stub
I'm manipulating few data with PHP, I have the choice between Json and XML.
I have noticed in the PHP regex library there is a choice between ereg
If I have a choice to use recursion or memoization to solve a problem
I would like to have the choice in a variable_load function (as used to
In general, If I have a choice when developing a web site to use
is the ruby mysqlplus adapter production ready? have a choice between: 1. mysql library
I want to provide a choice between streaming 'channels', if you will, in a
There are times when I have a choice between using a CSS element:hover or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.