title: Accessing return values from functions in C and C#
body: <p>I have a doubt regarding the concept of availability of return values from functions in C/C++ and C#. I know that it's not correct to return a pointer to the variables created in the function(local variables). In this case, if I wanted to create an array of values (say int) and return this array from the function how do I do this? And also if I return a local variable directly (not through a pointer to it) when is the memory allocated for this variable reclaimed by the runtime - is it after the value returned is assigned to the receiver of this value?</p>
  
  <p>Another related question is in C#: the variables created in a function using 'new' operator in C# are created on heap. Is it true in the case of local variables created in a function? If the values returned are by reference/address, isn't it violating the rule mentioned above(C++)? What is the way in which this is achieved in C#?</p>
  
  <p>My questions may seem naive, but I am trying to understand the behavior of compilers and runtimes better. It'd be of great help if you could provide me the answers for these questions.</p>
  
  <p>Thanks,
  Rakesh.</p>