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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:25:13+00:00 2026-05-26T14:25:13+00:00

Why should this be an error? int a = 0; a = 42; int

  • 0

Why should this be an error?

int a = 0;
a = 42;

int main()
{
}

A possibe match for this behavior i could find:

(3.4.1/4) A name used in global scope, outside of any function, class
or user-declared namespace, shall be declared before its use in global
scope.

Could this be a defect in standard?

  • 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-26T14:25:13+00:00Added an answer on May 26, 2026 at 2:25 pm
    int a = 0; //it is a declaration (and definition too) statement
    a = 42;    //it is an assignment statement
    

    The second line is the cause of error, for it is an assignment statement.

    At the namespace-level, only declaration and definition statements are allowed. Assignment-statements are not allowed at namespace level.

    And by “shall be declared before its use in global scope” (from the spec’s quotation) means the following:

    int a = 42;
    
    int b = 2 * a; //a is being used here
    
    int c = a + b; //both a and b are being used here
    

    If you define type instead, then:

    struct A {}; //definition of A
    
    struct B { A a; }; //a is declared as member of B 
                       //(which means, A is being "used") 
    
    void f(const A&, const B&); //both A and B are used in the declaration of f
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i get this error when trying this: ERROR method name expected. How should i
I got this weird error which mentions I should install VSTS 2008 SP1, during
Can anybody please spot my error, this should be a legal query in SQL
I have this query and I get error Operand should contain 1 column(s), whats
I'm not sure why I'm getting this error, but shouldn't this code compile, since
Should I be using this method of throwing errors: if (isset($this->dbfields[$var])) { return $this->dbfields[$var];
Should this be as easy as Trace.WriteInformation() in a C# file that is in
What is the accepted practice for indenting SQL statements? How should this example be
This should be fine seeing as the CLR hasn't actually changed? The boxes running
This should hopefully be a simple one. I would like to add an extension

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.