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..
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..