Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

How to make dynamic matrix?

matrix

  • Please log in to reply
5 replies to this topic

#1 Hamed

Hamed

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 413 posts

Posted 08 January 2011 - 05:20 AM

Hello,
I want to make dynamic matrix in c++ by using new by I don't know how to define pointers!
  • 0

#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 08 January 2011 - 05:43 AM

Why not use a std::vector?
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 Hamed

Hamed

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 413 posts

Posted 08 January 2011 - 05:49 AM

I can not use vector!
I need sth like * *p;
I don't know how to use it!
  • 0

#4 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 08 January 2011 - 08:13 AM

So you need something like a 2d array?
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#5 mnirahd

mnirahd

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 328 posts

Posted 08 January 2011 - 09:28 AM

Hi,

you can define dynamic array like that

  int rows = 6;  //this is an example this can have any value;
  int column = 6;

  int **DynamicMatrix = new int*[rows]; //we are going to create an integer dynamic matrix
  //The above statement creates memory for rows
  //the following statement creates memory for column for each row!
  for (int i = 0; i < rows; i++)
  {
      DynamicMatrix[i] = new int[columns];
  }
  

I hope this helps!

Munir
  • 0

#6 Hamed

Hamed

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 413 posts

Posted 08 January 2011 - 09:36 AM

Yes 2ed array.
Thanks!

Hi,

you can define dynamic array like that

  int rows = 6;  //this is an example this can have any value;
  int column = 6;

  int **DynamicMatrix = new int*[rows]; //we are going to create an integer dynamic matrix
  //The above statement creates memory for rows
  //the following statement creates memory for column for each row!
  for (int i = 0; i < rows; i++)
  {
      DynamicMatrix[i] = new int[columns];
  }
  

I hope this helps!

Munir


  • 0





Also tagged with one or more of these keywords: matrix

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download