Divide and conquer,multiple returns,get confused,How to code in proper way

I always face difficulty when i want multiple returns from single function.For eg:- You all now there is famous problem known as Maximum-subarray Problem(i.e contiguous subarray whose sum is maximum).
I was doing this question from divide and conquer approach. And i want left index,right index of maximum sum contiguous subarray and its sum also.
So Is there any way to handle this problem so that i can take all these information . I can’t return multiple values from function. And i saw at so many places in Pseudo code they write multiple values to be return . But its too difficult to convert such pseudo codes in real codes

Now i am going to give example of those Pseudo code which are given in C.L.R.S book(cormen) and i find myself in very difficult situation to code them

  1. I have already explained Maximum subarray problem .(in which they returned multiple values).
  2. Strassen’s algorithm for matrix multiplication using divide and conquer.

So any suggestions plz.
How can i improve myself regarding this.

I use one of these two ways to do this in C. Either pass your arguments by reference or make all the variables you want to access, global. By passing values by reference, you’re passing the address of those variables. Hence, when you modify them in your function, their values remain modified even after function call. Global variables, as the name suggests, are accessible throughout the code.I personally use global variables as they’re easier to use.
But remember, once you’ve modified your variables using these methods, older values are no more accessible unless stored explicitly elsewhere.

Note: These methods are basically eliminating the need to return from a function.

A similar question on stackoverflow: Returning multiple values from a function

1 Like

@sniper6 thanks a lot now i am comfortable with these . thanks for the link

@sniper6 Thank you very much .It really helped me alot.

You’re welcome! :slight_smile: