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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:37:26+00:00 2026-06-08T12:37:26+00:00

#include <iostream> using namespace std; int main(void) { int num[5]; const int* &ref =

  • 0
#include <iostream>

using namespace std;
int main(void)
{
    int num[5];
    const int* &ref = num;

    return 0;
}

I’ve read a C++ book which mentioned if a reference variable is referencing to:

  1. a variable where the type is different but can be converted.
  2. a variable that is not a Lvalue.

As long as the referencing variable is declare as const, the above 2 cases will be solved by using a method where the compiler will create a storage and the value will be placed into it while the identifier of the referencing variable is treated as the identifier for that particular storage location . Below is the demonstration code .

Case 1

#include <iostream>

using namespace std;
int main(void)
{
    int num = 5;
    const long long &ref = num; //the value 5 is place in a new storage where ref is the identifier

    return 0;
}

Case 2:

#include <iostream>

using namespace std;
int main(void)
{
    int num = 5;
    const int &ref = num + 1; //expression num + 1 evaluated and store in new storage with identifier ref

    return 0;
}

Since this 2 cases is valid, how come the case inside The Code: is invalid?

My logic is since the name of the array when used will be converted to pointer to the first element of the array , thus the compiler should’ve spotted this is not a lvalue and a new storage will be created to store that address along and of course , the referencing variable name will be taken as the identifier for that location .

Note : I know this is slightly out of topic , but may I know whether an array name is Lvalue or not? Just a simple yes or no will do , since changing the code to int &ref = num I assume it’s not a lvalue , but I just need further confirmation.

Thank you.

  • 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-06-08T12:37:27+00:00Added an answer on June 8, 2026 at 12:37 pm

    You reference variable is not declared const.

    There’s a difference between const int * and int * const, and you’ve picked the wrong one.

    Your example (ii) is invalid for the same reason, it should be const int &ref = num + 1;

    For your Note, I’m not sure that a simple yes or no will do. A simple array name is an lvalue, referring to the array. However, in most contexts it decays to a pointer-to-first-element, which is an rvalue pointer.

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

Sidebar

Related Questions

#include<iostream> #include<string> using namespace std; int main(void) { struct STRCT { int num; string
#include <iostream> using namespace std; int main(void){ int size = -2; int* p =
#include <iostream> #include <vector> using namespace std; int main(void) { int i, s, g;
#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int main(void) {
#include <iostream> using namespace std; int main (int argc, char* const argv[]) { int
The following code #include <iostream> using namespace std; int main() { const char* const
#include <iostream> #include <string> using namespace std; int main(void) { string a; cin>>a; a.erase(a.end()-1);
#include stdio.h #include conio.h #include <iostream> using namespace std; int main (void) { char
#include <stdio.h> #include <iostream> using namespace std; int main(void) { bool premiereLignefaite = false;
#include <iostream> using namespace std; int main(void) { int number, guess; srand(time(NULL)); number =

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.