Oct 25, 2014 at 5:32pm UTC
what is the advantage of using pointers?
will it give me more performance?
or what?
please give me some examples
and what is new
and why should i use it.
thank you.
code :
why should i use
int *input = new int
instead of
int input
Oct 25, 2014 at 6:26pm UTC
For Suppose:
you want to create an array for n number of items.(n will be known during execution).
so one way to do this is create a static array
int storage[max](max can be any value).
but for suppose if max=100 and if user input value is only 10 . so remaning 90 integer sets are waste of memory..
so we can do alternatively in another way using dynamic memory allocation(on heap)
cin>>n;
int *storage=new int(n);
so we will be allocating exactly n number of integer sets.