Re: Need help in my array
On Jun 6, 8:07 am, "sumedh....." <sumedhsak...@gmail.com> wrote:
Array is nothing but a pointer..
Nonsense. Arrays and pointers are two completely different
things.
that means: int p[4]; can be
represented as *(p+i)
I think you mean that the expression p[i] is the same as *(p+i).
This is a misfeature of C, and doesn't hold if you use C++ style
arrays (i.e. std::vector). And it only holds in expressions; it
has nothing to do with the type of any objects.
so another way of declaring it is
int *p=new int[n]; //and n doesnot need to be a constant..
There is never any reason to use array new in C++. The correct
way to declare an array is:
std::vector< int > array( n ) ;
About the only exception is when you need static initialization,
to avoid order of initialization issues.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34