Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,111 questions

40,781 answers

573 users

How to use references to float in C++

1 Answer

0 votes
#include <iostream>

using std::cout;
using std::endl;

int main()
{
	float f = 3.14F;
	float  &ref = f;

	cout << "f = " << f << "  ref = " << ref << endl;

	ref *= 3;
	cout << "f = " << f << "  ref = " << ref << endl;

	const float &cref = f;
	
	cout << "f = " << f << "  cref = " << cref << endl;

	//cref *= 4; // Error C3892 'cref': you cannot assign to a variable that is const	

	return 0;
}

/*
run:

f = 3.14  ref = 3.14
f = 9.42  ref = 9.42
f = 9.42  cref = 9.42

*/

 





answered May 23, 2018 by avibootz

Related questions

1 answer 126 views
126 views asked Mar 2, 2021 by avibootz
1 answer 40 views
1 answer 85 views
85 views asked May 23, 2018 by avibootz
3 answers 147 views
...