Return By Value, Return By Pointer, Return By Reference
Return By Value, Return By Pointer, Return By Reference Return by value: In this the function returns some kind of value like the variable, it is the most simplest way to return the value. remember it will return a copy of the variable, and it also doesn't affect the scope of the variable. int * myFunction() { . . . } Example: int doubleValue(int x) { int value = x * 2; return value; // A copy of value will be returned here } Return by Pointer/Address: return by pointer also known as return by address. in this type the address of the variable is returned. return by address can only return the address of a variable, not a literal or an expression (which don’t have addresses). if you try to return the address of a variable local to the function, your program will exhibit undefined behavior. Consider the following example: int* doubleValue(int x) { int value = x * 2; return &value; // return value by address here } in the above example the scope of the va