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 7892627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:55:09+00:00 2026-06-03T06:55:09+00:00

Are the following declarations correct? Outside any function: int a; //external by default extern

  • 0

Are the following declarations correct?

Outside any function:

int a; //external by default
extern int a; //explicitly extern
static int a; //explicity static
const int a; //static by default
static const int a; //explicitly static
extern const int a; //explicitly extern

Inside a function:

int a; //auto by default
static in a; //explicity static
const int a; //static by default
static const int a; //explicitly static
  • 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-03T06:55:11+00:00Added an answer on June 3, 2026 at 6:55 am

    Close.

    Anything at global scope (ie: outside a function) is static by default.

    eg:

    //main.c
    int myVar;  // global, and static
    
    int main(void) {
      ...
      return 0;
    }
    
    //morecode.c
    extern int myVar; //other C files can see and use this global/static variable
    

    However, if you explicitly declare something at the global scope as static, not only is it static, but it is only visible inside that file. Other files can’t see it.

    //main.c
    static int myVar;  // global, and static
    
    int main(void) {
      ...
      return 0;
    }
    
    //morecode.c
    extern int myVar; // compiler error; "myVar" can only be seen by 
                      // code in main.c since it was explicitly 
                      // declared static at the global scope
    

    Also, nothing is “extern” by default. You typically use extern to access global variables from other files, provided they weren’t explicitly declared static as in the example above.

    const only implies that the data cannot change, regardless of it’s scope. It does not imply extern, or static. Something can be “extern const” or “extern”, but “extern static” doesn’t really make sense.

    As a final example, this code will build on most compilers, but it has a problem: myVar is always declared “extern”, even in the file that technically creates it. Bad practice:

    //main.c
    extern int myVar;  // global, and static, but redundant, and might not work
                       // on some compilers; don't do this; at least one .C file
                       // should contain the line "int myVar" if you want it 
                       // accessible by other files
    int main(void) {
      ...
      return 0;
    }
    
    //morecode.c
    extern int myVar; //other C files can see and use this global/static variable
    

    Finally, you might want to cover this post on the various levels of scope if you are not already familiar with them. It will likely be helpful and informative to you. Good luck!

    Terminology definition – Scope in C application

    The person who answered this question of mine on scope did a good job, in my opinion.

    Also, if you declare something static within a function, the value remains between function calls.

    eg:

    int myFunc(int input) {
      static int statInt = 5;
      printf("Input:%d  statInt:%d",input,statInt);
      statInt++;
      return statInt;
    }
    
    int main(void) {
      myFunc(1);
      myFunc(5);
      myFunc(100);
      return 0;
    }
    

    Output:

    Input:1  statInt:0
    Input:5  statInt:1
    Input:100  statInt:2
    

    Note that the use of a static variable within a function has a specific and limited number of cases where they are useful, and generally aren’t a good idea for most projects.

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

Sidebar

Related Questions

What is the difference between the following declarations? char * const a; const char
What is the difference between the following two declarations? Class.method = function () {
If I have the following pointer variable declarations: int *a; int **c; Regarding to
I have faced the following interview question. Consider this function declaration: void quiz(int i)
I have a controller/model hypothetically named Pets. Pets has the following declarations: belongs_to :owner
I have the following interface declarations: interface IOrder<T> where T: IOrderItem { IList<T> Items
What's the difference between the following two declarations? I thought they were equivalent, but
I see the following in the declarations section at the top of a .cs
using the following set of rules and style declarations .tableRow.even, .tableRowNS.even, .odd { background-color:
A traditional C++ class (just some random declarations) might resemble the following: class Foo

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.