Consider this function int&(int*,int&,&int) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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?????

25th Nov 2016, 5:17 PM
sadia sharif
1 Answer
+ 2
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.
21st Dec 2016, 5:28 AM
Yuval Keren
Yuval Keren - avatar