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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:08:42+00:00 2026-05-16T05:08:42+00:00

include static int i = 10; int main() { static int i = 20;

  • 0

include

static int i = 10;

int
main()
{
   static int i = 20;

   printf ( "i = %d\n", i );

   return 0;
}

There are two static variables, one in global scope and one in function scope. The compiler is not throwing “multiple definition” error.
Could you please let me know where the two static vars are stored?

  • 1 1 Answer
  • 1 View
  • 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-16T05:08:43+00:00Added an answer on May 16, 2026 at 5:08 am

    The two variables are stored separately because they are distinct – it is the compiler’s problem to ensure that they are separate.

    The variables are both initialized before the program starts – this is C, not C++, where the rules are slightly different.

    Inside main() as shown, you cannot access the global variable i (again, this is C, not C++).

    GCC’s -Wshadow compiler flag would warn you about the local i shadowing the global one.

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

Sidebar

Related Questions

Consider this code: one.c: #include <stdio.h> int one() { printf(one!\n); return 1; } two.c:
I have such a program: #include <stdlib.h> #include <iostream> static int pswd=0; int main()
I have two files: #include <stdio.h> static inline void print0() { printf(Zero); } static
#include<stdio.h> int fact(int i); void main() { int j; j=fact(4); printf(%d,j); } int fact(int
I have the following code: #include <boost/shared_ptr.hpp> struct Foo { int a; }; static
If I have a global static variable x like in this code #include <stdio.h>
#include<stdio.h> class A { public: int a;}; class B: public A { public: static
In the Bird class, there is one virtual function canFly() which is implemented in
When defining a global or static array in c++ its memory is not immediately
I was going through the code at http://geeksforgeeks.org/?p=10302 #include<stdio.h> int initializer(void) { return 50;

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.