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

  • Home
  • SEARCH
  • 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 8161823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:34:49+00:00 2026-06-06T18:34:49+00:00

When I first started programming I always followed the convention of defining global variables

  • 0

When I first started programming I always followed the convention of defining global variables at the top of the file like:

static int a[10];
static int b[10];

void firstFn(void)
{
    a[0] = 1;
}

void secondFn(void)
{
    b[4] = 2;
}

void thirdFn(void)
{
    b[5] = 2;
}

But lately I was working on something where I wanted the definition of a global variable to be grouped with a few functions that operate on that variable defined further down in the file:

static int a[10];

void firstFn(void)
{
    a[0] = 1;
}

static int b[10];

void secondFn(void)
{
    b[4] = 2;
}

void thirdFn(void)
{
    b[5] = 2;
}

Another programmer was reviewing this code and said this was one of his pet peeves. Is there a good reason to stick to the top-defining convention?

  • 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-06-06T18:34:50+00:00Added an answer on June 6, 2026 at 6:34 pm

    Static variables are local to your compilation unit. Their placement makes absolutely no difference, as long as they are declared ahead of their first use in the program.

    Although there are no purely technical reasons to keep static declarations at the top of the file, this is a rather widespread convention. I’ve seen it written out explicitly in the coding standards of several companies. When all programmers follow the same convention, the code looks more uniform, and uniformity is a great step toward code maintainability. When someone else opens your file and the code formatting looks familiar, that’s a great plus. So if other colleagues on your team do follow this convention, you should follow it as well.

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

Sidebar

Related Questions

I just started learning my first real programming language, Python. I'd like to know
I have just started the Assembly language programming and in the first lecture our
Well, I've started with iPod/iPhone programming using Head First iPhone Development (O'reilly) and I'm
This is my first question at stackoverflow :-). However, I've started to Android programming
When I first started programming in .NET I used try/catches all the time. I
When I was first started teaching myself programming, after finishing a tutorial I would
I recently started programming my first Cocoa app. I have ran into a problem
I started programming in perl few months back and this is my first question
I've just started programming a online highscore for the first time, and it's for
Like many other people posting questions here, I recently started programming in Python. I'm

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.