if possible then how to return more than one value. It can not be because of return is done through Accumulator in controller or CPU.
Is this is the correct reason?
if possible then how to return more than one value. It can not be because of return is done through Accumulator in controller or CPU.
Is this is the correct reason?
Because that's how the language is defined. There is no fundamental reason; other languages can return multiple values (e.g. Matlab).
As a "workaround", you can return a struct that contains multiple fields.
You can totally "return" more than 1 item by putting them into a struct, or pass a pointer to the function so that the function can write some value that persists after the function has returned.
You cannot return more than one value at a time. because the syntax for returning a function is defined in such a way that it should accept only one value. check the below example.
a=returnfunction();
In the above case if the function returnfunction() returns more than one value, then the compiler gets confused to initialize which returned value to the variable a. if the function returnfunction() returns two values 1 and 2, then the compiler get confused of assigning the value 1 or 2 to the variable a. so in order to prevent these type of problems the functions are defined in such a way to not to return more than one value.
Contrary to how it's expressed, no value actually gets "returned". In fact the return value/address is passed as an argument on stack to the function call. Then the return statement actually modifies that argument, thus passing result to the caller.
In some sense, it's almost like void func(arg1, arg2, *ret)
Different languages handle this differently. C expects only one "return" argument on stack. Indeed structure will let you "return" multiple values, so would passing a pointer to a structure as a normal argument do as well.