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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:50:38+00:00 2026-05-27T12:50:38+00:00

Consider the following code-snippet typedef int type; int main() { type *type; // why

  • 0

Consider the following code-snippet

typedef int type;
int main()
{
   type *type; // why is it allowed?
   type *k ;// which type?
}

I get an error 'k' is not declared in this scope. The compiler parses type *k as multiplication between type* and k. Isn’t this grammar very confusing?

Why is type *type allowed by the C++ Standard? Because the grammar says so? Why?

  • 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-27T12:50:38+00:00Added an answer on May 27, 2026 at 12:50 pm

    The question is actually about when exactly a variable name is defined as an identifier, and the language determines that it is right after the point in code where the variable is declared:

    typedef int type;
    int main() {
       type t;   // type refers to ::type
       int       // type still refers to ::type
       type;     // variable declared, this shadows ::type
       type + 1; // type is a variable of type int.
    }
    

    There are similar rules in other contexts, and it is just a matter of deciding when identifiers are declared. There are other similar situations, for example in the initialization list of a class:

    struct test {
       int x;          // declare member
       test( int x )   // declare parameter (shadows member)
       : x(            // refers to member (parameter is not legal here)
            x )        // refers to parameter
       {};
    };
    

    Or in the scope of the identifiers in the definition of member functions:

    struct test {
       typedef int type;
       type f( type );
    };
    test::type         // qualification required, the scope of the return type is
                       // at namespace level
    test::f(
             type t )  // but the scope of arguments is the class, no qualification
                       // required.
    {}
    

    As of the rationale for the decision, I cannot tell you but it is consistent and simple.

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

Sidebar

Related Questions

Consider the following code snippet: class Test { public int Length{ get; set; }
Consider the following snippet of code: // get number of sheep in DataTable by
Let's consider the following code snippet in Java. package escape; final public class Main
Consider the following code snippet import qualified Foreign.Concurrent import Foreign.Ptr (nullPtr) main :: IO
Consider the following 2 code snippets: Case 1: #include <iostream> int main() { int
Consider the following code snippet: #!/bin/bash #This program tests the if statement in bash.
Consider the following Code snippet, Assembly asm = Assembly.LoadFile(DLL_Path); Type t = asm.GetType(DLL_NameSpace.MyClass, false,
Consider the following code snippet: int index = FindClosestIndex(frame); if (_data[index].Frame == frame) return
Consider the following code snippet: std::vector<int> v; v.reserve(100); v.insert(v.end(), 100, 5); v.erase(v.begin(), v.end()); std::cout
Consider the following code: #include <stdio.h> int main (void) { char str1[128], str2[128], str3[128];

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.