cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
R1 is a reference bound to 1
R1 is a reference bound to 1
Mar 17, 2016 at 9:32am UTC
EnigmaticZee
(16)
ri is a reference bound to i so how come it prints 10, 10 ?
1
2
3
int
i, &ri = i; i = 5; ri = 10; std::cout << i <<
" "
<< ri << std::endl;
Mar 17, 2016 at 9:36am UTC
Peter87
(11235)
ri
refers to
i
so when you do
ri = 10;
you are setting the value of
i
to 10.
Last edited on
Mar 17, 2016 at 9:37am UTC
Mar 17, 2016 at 9:50am UTC
EnigmaticZee
(16)
It's ri = 10 and nowhere it says i = ri
Mar 17, 2016 at 9:56am UTC
Peter87
(11235)
See that & on the first line? That means
ri
is a
reference
to
i
. You can think of
ri
as an alternative name for
i
. When you use
ri
in the code you are actually using
i
.
Topic archived. No new replies allowed.