C++ Programming - References - Discussion
Discussion Forum : References - General Questions (Q.No. 1)
1.
Which of the following statement is correct?
Discussion:
25 comments Page 2 of 3.
Wouter van ooijen said:
1 decade ago
A reference is syntactic sugar for a pointer. It it can be stored either global, on the stack, or on the heap.
int a;
int &b{ a }; // global.
f(){
int &b{ a }; // on the stack.
}
struct ref{ int &b; ref( int &x ): b{ x }{} };
ref * p = new( a ); // p->b is on the heap.
int a;
int &b{ a }; // global.
f(){
int &b{ a }; // on the stack.
}
struct ref{ int &b; ref( int &x ): b{ x }{} };
ref * p = new( a ); // p->b is on the heap.
Velmurugan said:
1 decade ago
Reference is a variable&data declaration part in your program. (i.e int a =6).
Ramesh said:
1 decade ago
Reference is also a variable declared in a function. That should be stored in stack.
Sourabh k said:
1 decade ago
Its true that reference is stored in stack.
Cause reference just point or refer to any local variable.
And any local variable has stack memory.
So Indirectly reference is stored in stack.
Cause reference just point or refer to any local variable.
And any local variable has stack memory.
So Indirectly reference is stored in stack.
(1)
Chandan said:
1 decade ago
A reference is stored on heap because dynamically allocation is stored in heap and reference create at run time. So yes its 100% right.
Stack is used to store local variable basically.
Stack is used to store local variable basically.
(1)
Bindu said:
1 decade ago
Reference type stored in heap not stack.
(1)
Sunil brahmajosyula said:
1 decade ago
@valsala shukla.
Even pointers should be stored in queue?
Even pointers should be stored in queue?
Muhammad Qamar Saleem said:
1 decade ago
References store address of objects and only refer to objects. They are used only as a pointer.
Mahesh Hirpara said:
1 decade ago
What say not possible reference stored on stack ? when it possible?
Arpita sahoo said:
1 decade ago
What is constant?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers