Noob question about & and const

Hi, could someone be kind enough to explain me this piece of code?

 
  const int*const Method3(const int*const&)const;



Last edited on
const means the variable will never change.
int aka signed int is an integer, 4 bytes, the limits are –2,147,483,648 to 2,147,483,647.
* is a pointer, a pointer points to another variable's address.
Method3 is the name of the variable.
i don't think it's a varible, more like method declaration
Last edited on
Good point.
In this case the return type is a constant pointer to a constant integer and the parameter is a reference to a constant pointer to a constant integer. The const after the function means it is a member function(method) of a class and it promises not to modify any of the member variables.

By the way @Bob
Bob The Zealot wrote:
int aka signed int is an integer, 4 bytes, the limits are –2,147,483,648 to 2,147,483,647.
This is not always the case it is dependent on the compiler. http://www.cplusplus.com/doc/tutorial/variables/

Oh and something I forgot to mention earlier is that the keyword const binds to the left unless it is the first keyword then it binds to the right. so const int is the same as int const
Last edited on
The word const refers to the identifier to its left, the exception to the rule is that the first identifier's const can be on the left:

1
2
3
4
5
6
7
const int;         // constant int
int const;         // constant int
const int *;       // pointer to constant int
int const *;       // pointer to constant int
const int * const; // constant pointer to constant int
int const * const; // constant pointer to constant int
int * const;       // constant pointer to non-constant int 


Last edited on
Thanks it helps alot, I get it now!
Your welcome Geranimo, thanks to LowestOne and giblit.
Topic archived. No new replies allowed.