Consider this function int&(int*,int&,&int) | SoloLearn: Learn to code for FREE!


Consider this function int&(int*,int&,&int)

what does the return type int& and the arguments of function that are int* int& and &int mean????So what if return type is &int or int* or *int?????

11/25/2016 5:17:07 PM

sadia sharif

1 Answer

New Answer


Hi! first of all, there not such a thing "&int" as an argument or return value, this is an address access operator which returns the address of the variable. A int& return type simply means it returns a reference (address) of an EXISTING integer variable, same goes for int& as an argument, the function takes a reference to an integer instead of creating a new variable copy of it. An int* is a pointer type, it's a variable that exists in memory (in contrast to a reference which is compile-time handled) and holds an address of an int type. Whether you choose to use references or pointers or both is up to you, pointers give you more flexibility and freedom while references are simpler and save memory, but eventually they have the same purpose.