You can pass a const to a const reference, but it has to be a memorized value in memory. When you use functionA(500); you are using a literal which doesn't take any memory.
You can pass a const to a const reference, but it has to be a memorized value in memory. When you use functionA(500); you are using a literal which doesn't take any memory.
A const reference can bind to a temporary, which is what happens in this case. A temporary int is initialized with the value 500 and fed as a reference to functionA (assuming the call isn't inlined.)
Arrandale wrote:
When functionA receive 500, Where address of "&number" refer to?
& doesn't have anything to do with an address in this context. All it says is that the whatever is passed to functionA will be passed by (const) reference. In other words number will be an alias for whatever variable or value was fed to the function.