Query on new operator

  • Thread starter bharath.donnipad
  • Start date
B

bharath.donnipad

Hi all,

I was going through "new" syntax and wrote a small program:

#include <iostream.h>
#include <stdlib.h>

int main()
{ //int *intp = new int (7); //create a new location for intp and
initialize location pointed by intp with 7;
int *intp = new int[2](7,17); //does this initialize 2 locations
of int with 7,17 ??
std::cout<<intp[0]<<endl<<intp[1]<<endl;
delete intp;
system("PAUSE");
return 0;
}

As per "new" syntax & its description given URL:
http://www.scs.stanford.edu/~dm/home/papers/c++-new.html, under
sub-heading "Memory allocation in C++" I understood that int *intp =
new int[2](7,17); statement should initalize two locatons created with
7 and 17. But when I ran program it's giving output as:
0
0

in my DevC++ compiler. I dont understand why its initalizing intp with
7 in one case and not in other where array of locations is created....

Please explain me..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,201
Messages
2,571,051
Members
47,656
Latest member
rickwatson

Latest Threads

Top