| fme (3) | |
|
hello eveyone. 1) i am working in stack program and i know that if i say x=&y; that means the address of y was assigned to x. but i am not understand is when using it like: const int & top() const; 2) here what the issue of saying const in the right an left thanks | |
|
Last edited on
|
|
| exception (323) | |||
const int & top() const;Is the declaration of a function top() returning a reference to a int which cannot be changed through the reference. The function itself is const, meaning it doesn't change any object/class variables (except they are declared mutable). const int* x (or const int& x) is a pointer/reference to a const int, i.e. the value pointed to cannot be changed. int* const x means that the pointer value (i.e. the address pointed to) cannot be changed, but the value pointed to can be altered. Example:
| |||
|
|
|||
| fme (3) | |
| thaaaaaaaaanks | |
|
|
|