How to return array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sanketbarot
    New Member
    • Sep 2006
    • 30

    How to return array

    I have made one function which will get value for m * n matrix.

    int *matrix_read()
    {
    int i,c,r;
    static int *q;
    cout<<"Enter value of M and N for M * N matrix";
    cin>>c>>r;
    int *p=new int(r*c);
    q=p;
    for (i=0;i<r;i++)
    {
    cout<<"Enter"<< i+1<<"Row value";
    for (int j=0;j<c;j++)
    {
    cin>>*p;
    p++;
    }
    }
    return q;
    }

    Now the problem I am facing is that how can I return the size of the matrix. Means If I want to display the same matrix then I must know the size of the matrix. How can i do this?
  • m013690
    New Member
    • Sep 2006
    • 23

    #2
    Make your matrix a class with members that specify the dimensions...

    Comment

    • sanketbarot
      New Member
      • Sep 2006
      • 30

      #3
      the thing is I have to do this task using only function. That is why I am confused.

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        You pointer parameters to point to locations to store the width and height

        int *matrix_read(un signed *pWidth, unsigned *pHeight)
        {
        ...
        }

        Comment

        • ltgbau
          New Member
          • Sep 2006
          • 41

          #5
          note: you have to free memory references by the returned pointer after using it

          Comment

          Working...