Jump to content

How to make dynamic matrix?

- - - - -

  • Please log in to reply
5 replies to this topic

#1
Hamed

Hamed

    Programming Professional

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

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 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
Why not use a std::vector?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Hamed

Hamed

    Programming Professional

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

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 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
So you need something like a 2d array?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
mnirahd

mnirahd

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 330 posts
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

#6
Hamed

Hamed

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 276 posts
Yes 2ed array.
Thanks!

mnirahd said:

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users