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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:23:50+00:00 2026-05-20T10:23:50+00:00

With #include <iostream> using namespace std; int a = 1; int main() { int

  • 0

With

#include <iostream>
using namespace std;

        int a = 1;

int main()
{
        int a = 2;

        if(true)
        {
                int a = 3;
                cout << a 
                     << " " << ::a // Can I access a = 2 here?
                     << " " << ::a << endl;
        }
        cout << a << " " << ::a << endl;
}

having the output

3 1 1
2 1

Is there a way to access the ‘a’ equal to 2 inside the if statement where there is the ‘a’ equal to 3, with the output

3 2 1
2 1

Note: I know this should not be done (and the code should not get to the point where I need to ask). This question is more “can it be done”.

  • 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-20T10:23:51+00:00Added an answer on May 20, 2026 at 10:23 am

    No you can’t, a (2) is hidden.

    Ref: 3.3.7/1

    A name can be hidden by an explicit
    declaration of that same name in a
    nested declarative region or derived
    class (10.2).

    Ref: 3.4.3/1

    The name of a class or namespace
    member can be referred to after the ::
    scope resolution operator (5.1)
    applied to a nested-name-specifier
    that nominates its class or namespace.
    During the lookup for a name preceding
    the :: scope resolution operator,
    object, function, and enumerator names
    are ignored. If the name found is not
    a class-name (clause 9) or
    namespace-name (7.3.1), the program is
    ill-formed.

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

Sidebar

Related Questions

#include <iostream> using namespace std; int main() { cout << !!!Hello World!!! << endl;
#include <iostream> using namespace std; int main() { double u = 0; double w
Example: #include <iostream> using namespace std; int main() { wchar_t en[] = LHello; wchar_t
The following code #include <iostream> using namespace std; int main() { const char* const
Short problem: #include <iostream> using namespace std; int main() { double **T; long int
#include <iostream> #include <vector> using namespace std; int main() { vector< vector<int> > dp(50000,
#include <iostream> #include <fstream> using namespace std; int main () { ofstream myfile; myfile.open
#include <iostream> #include <vector> using namespace std; int main(void) { int i, s, g;
I have this code #include <iostream> using namespace std; int main(int argc,char **argv) {
Consider the following code: #include <iostream> using namespace std; int main() { int x,

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.