|
-
September 16th, 2010, 11:02 AM
#1
Reference Variable Query
Consider the following code:
Code:
const int con = 100;
int &ref1 = 10; //Where is this 10 stored?
int &ref2 = con;
ref1 = 20;
ref2 = 90;
cout<<ref1<<con<<ref2;
This outputs: 20 100 90
My only queries are:
a) Where is the hard coded number 10 stored?
b) When ref1 is modified which memory was modified? (10's or ref1 has it's own memory)
c) Why was const variable not modified but somehow it's reference was?
Regards,
Nisheeth Barthwal
-
September 16th, 2010, 11:05 AM
#2
Re: Reference Variable Query
Ummm...that shouldn't compile.
-
September 16th, 2010, 11:29 AM
#3
Re: Reference Variable Query
-
September 16th, 2010, 12:03 PM
#4
Re: Reference Variable Query
nvm, this is not a standard code just found out.
int const &ref = 10; //legal
so
ref = 3; //illegal
turns out fine.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|