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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:36:22+00:00 2026-05-27T16:36:22+00:00

int x = 12; 12 is said to be integer literal, and therefore can’t

  • 0
int x = 12;

12 is said to be integer literal, and therefore can’t be used in the LValue.

  1. How does the compiler allocate memory to a literals?
  2. What is the scope of a literals?
  3. Why can’t we get its address with an &12 in its scope?
  • 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-27T16:36:22+00:00Added an answer on May 27, 2026 at 4:36 pm

    OK Bad example in the question.
    But the question is still valid:
    Lets try:

    Foo getFoo() {return Foo();}
    
    int func()
    {
        getFoo().bar();   // Creates temporary.
        // before this comment it is also destroyed.
        // But it lives for the whole expression above
        // So you can call bar() on it.
    }
    
    int func2()
    {
        Foo const& tmp = getFoo();  // Creates temporary.
                                    // Does not die here as it is bound to a const reference.
    
        DO STUFF
    }  // tmp goes out of scope and temporary object destroyed.
       // It lives to here because it is bound to a const reference.
    

    How does the compiler allocate memory to a temporary object?

    Undefined up-to the compiler.
    But it would be real easy to allocate a tiny bit more memory onto the stack frame and hold it there. Then destroy it and reduce the size of the stack frame (though this answer makes a whole lot of assumptions about the underlying hardware that you should never do (best just to think of it as the compiler doing magic)).

    What is the scope of a temporary object?

    The temporary object lives until the end of the expression (usually the ;) unless it is bound to a const reference. If it is bound to a const reference then it lives to then end of the scope that the reference belongs too (with a few exceptions (like constructors)).

    Why can’t we get its address with an &12 in its scope?

    In the question 12 is not a temporay object.
    It is an integer literal.

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

Sidebar

Related Questions

As of Java 1.5, you can pretty much interchange Integer with int in many
int i = 0; int k = Integer.parseInt(12); int j = k; System.out.println(i+1 +
int n ; n= (int)( javax.swing.JOptionPane.showInputDialog(null,enter a 3 digit no.)); Why does the above
Suppose we've got two integer and character variables: int adad=12345; char character; Assuming we're
auto_ptr on wikipedia said that an auto_ptr containing an STL container may be used
I run all my integers through a (int)Integer to make them safe to use
I’m trying to determine the relationship of a given compiler’s integer types’ sizes using
int a = 2; Console.WriteLine(a.ToString()); // displays 2 // definition of ToString() here -
int a[2]={1210,15}; printf(%d,a[33] ); OUTPUT 1073828132 Why it's not throwing error when i'm trying
int test_malloc(void **ptr, size_t size) { (*ptr) = malloc(size); return 0; } int test_app()

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.