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

The Archive Base Latest Questions

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

const int &ra=3; As I know, making ra const will extends the lifetime of

  • 0
const int &ra=3;
  1. As I know, making ra const will extends the lifetime of the temporary r-value which is in this case 3. This is a little bit confusing, as I know ra should have the same address as r-value which is here 3, but 3 is not a real variable and it does not have a memory where it’s stored. So how can this be possible?

  2. what is the difference between:

    const int& ra=a;
    

    and

    int& const ra=a;
    
  • 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-31T05:09:08+00:00Added an answer on May 31, 2026 at 5:09 am

    but 3 is not a real variable and it does not have a memory where it’s stored. so how can this be possible ?

    Actually a temporary object gets created out of the literal 3, and then that temporary is bound to the const reference. That is how it becomes possible.


    Now your next question: the difference between these two

    const int& ra=a;
    int& const ra=a;
    

    is that the second statement is illegal.

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

Sidebar

Related Questions

Given a class like this: class Foo { public: Foo(int); Foo(const Foo&); Foo& operator=(int);
Given the following: StreamLogger& operator<<(const char* s) { elements.push_back(String(s)); return *this; } StreamLogger& operator<<(int
I know that if you write void function_name(int& a) , then the function will
I saw someone using this in one answer: void methodA(const int*& var); I couldn't
int main() { const int maxint=100;//The program will crash if this line is put
struct G{ G&operator()(const int**a) { v<<a; std::copy(v.begin(),v.end(),std::ostream_iterator<int>(std::cout, )); return *this; } friend std::vector<int>&operator<<(std::vector<int>&v,const int**
void DoWork(int n); void DoWork(const int &n); What's the difference?
Consider the following: int ival = 1.01; int &rval = 1.01; // error: non-const
template <class T> bool BST<T>::search(const T& x, int& len) const { return search(BT<T>::root, x);
consider the following code: const QString& MyClass::getID(int index) const { if (i < myArraySize

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.