It looks like they should be the same to me too, but you have made a few mistakes. newint* allocates 1 pointer and newint allocates 1 integer, so G[0][0] is the only valid element you should access. The rest is out of bounds so what you have here is undefined behaviour which means you can't be sure what will happen.
You probably want to allocate arrays of size 4 instead. newint*[4] allocates 4 pointers and newint[4] allocates 4 integers. Note that you should now use delete[] instead of delete when freeing the memory.
I know that i can consider a pointer like an array and so I can create it dynamically for example so:
1 2 3 4
int *p=newint;
p[0]=0;
p[1]=23;
....
I create only a new address in which I can store an integer but at the same time with the array's notation I can do a dynamic array!
At the same way I can do it for a matrix, but in a real terms I must make a program that ask you the matrix's dimension (m rows and n columns) so i thinked something like:
1 2 3 4 5 6 7 8 9
...
int **G = newint*[m]; //creates an array of pointers
for(int i=0; i<m; i++)
{
G[m] = newint; //creates a start point for an array of int
for(int j=0; n<4; n++) //then i 'feed' every element ;)
G[m][n] = m+n;
}
...
This is what I really searched for :P Do you think is a good way? There is another better
Is this the best way? Probably not. It would have been easier use to std::vector if you knew how.
Do I recommend you to use std::vector in this program? Not necessarily. What you are doing is a good exercise in how pointers and arrays work and that is something that every C++ programmer should know. After you have become comfortable with pointers and arrays you will better be able to appreciate std::vector and to understand how it really works.
In your updated code you need to allocate an array on line 5. You also need to make sure you use the correct variables as indices and the loop condition for the inner loop is incorrect. Otherwise it looks like it's going to work.
thank you very much for spnt your time for me ;) I've correct the code instantly :) and i've understand a little bit more the c++ :P
The reason for my choise of not using std::vector is dictated by my professor ;) he want a program that using only the <iostream>!
IMHO I think it's a really cool stuff because he force me to squeeze any drop of my creativity and at the same time I can understand much more well the potentiality of this language and how it works in the inside, exactly just like you said.
Thanks very much again!! :)
P.S.: the errors about indices and loop condition are caused only by my haste to write :P