0

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,

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by MicrosoftMahmou
1

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.

Votes + Comments
Directly to the point! Short and very well explained :)
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.