hi every one,

As I said earlier i am very very beginner in c++ and programming in general .Then,I hope you bear with me and help me.

in pointer: if i definition a pointer as integer
**********************************
int **p = new int*[M];

for ( int i = 0; i < M; i++ )
p = new int[N];
*********************************
my question is : in this code what is ,,,,p,,,,, mean?

thank you,

Your first line creates an array of int pointers.

The p line allocates memory to each of those pointers, in effect created an 2-dimensional array of ints. So, each p is the name of a single 1D array of int.

commented: Directly to the point! Short and very well explained :) +4

The type of p is obviously a pointer-to-int.
While the type of p is pointer-to-pointer-to-int.
The type of *p and p[j] is an int.

vmanes>>So, each p is the name of a single 1D array of int.

Actually, because of the infamous analogy of pointer and arrays, few often ignore that they are actually not the same thing. Nevertheless, it doesn't matter here. But strictly speaking, the OP explicitly declared p as pointer-to-pointer-to-int hence p is not an array but a pointer-to-int
Although, I appreciate you being more simple.

vmanes , siddhant3s
thank you for your reply
it has become clear now

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.