Total members 11890 |It is currently Mon May 06, 2024 4:46 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





cpp code
#include <iostream>

using namespace std;

// This simply sets a to a function of b.
void fred(int &a, const int &b)
{
a = 2 * b * b;

// This would be illegal:
// b = 10;
}

main()
{
int m;

fred(m, 17);
cout << "m = " << m << endl;

int c = 45;
fred(m, 2*c + m);
cout << "m = " << m << endl;
}


The const modifier on a reference parameter means that the function will not change the item referred to.

Note that it is allowed to pass an expression parameter to a const reference, since it will not be assigned.

We'll find more use for this feature later, when we start flinging around things larger than integers and floats.



_________________
Please recommend my post if you found it helpful


Author:
Beginner
User avatar Posts: 95
Have thanks: 2 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Constant References
 Boolean type constant     -  
 Functions and References     -  
 References confuse me. How do they differ from pointers?     -  



Topic Tags

C++ Variables
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com