about int &const T and int const& t

Source: Internet
Author: User

#include <iostream.h>
#include <stdio.h>

int main ()
{
int i = 0;
int const& j = i;
int & Const T = i;
const int& m = i;
i = 3;

printf ("j =%d m =%d T =%d i =%d &j =%d &m =%d &t =%d", j,m,t,i,&j,&m,&t);
GetChar ();
}

GCC compilation results:

int & Const T = i; does not pass


#include <iostream>
#include <stdio.h>


int main ()
{
int i = 0;
int const& j = i;
int & Const T = i;
Const int& m = i;
i = 3;
j=4;
m=5;


printf ("J =%d m =%d i =%d &j =%d &m =%d", j,m,i,&j,&m);
GetChar ();
}

GCC compiles the pass-through statement:

i = 3;
j=4;


#include <iostream>
#include <stdio.h>


int main ()
{
int i = 0;
int const& j = i;
int & Const T = i;
Const int& m = i;
i = 3;




printf ("J =%d m =%d i =%d &j =%d &m =%d", j,m,i,&j,&m);
GetChar ();
}


Output:



int const & J = I shows that j is a constant reference to int i, so this means that the value of I cannot be changed by T. However, since I is a variable, I can change the self-born value, and T is a reference to the variable I so she only refers to the value of variable I, so of course I change the value.

about int &const T and int const& t

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.