| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"" |
| Date: |
03 Sep 2006 03:12:15 PM |
| Object: |
Query on new operator |
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..
.
|
|
| User: "Jens Theisen" |
|
| Title: Re: Query on new operator |
03 Sep 2006 03:53:01 PM |
|
|
"bharath.donnipad@gmail.com" <bharath.donnipad@gmail.com> writes:
int *intp = new int[2](7,17);
That's not standard C++. Maybe it's a microsoft extension.
Jens
.
|
|
|
| User: "Frederick Gotham" |
|
| Title: Re: Query on new operator |
03 Sep 2006 05:45:58 PM |
|
|
Jens Theisen posted:
"bharath.donnipad@gmail.com" <bharath.donnipad@gmail.com> writes:
int *intp = new int[2](7,17);
That's not standard C++. Maybe it's a microsoft extension.
Or perhaps the comma operator.
--
Frederick Gotham
.
|
|
|
| User: "Thomas Tutone" |
|
| Title: Re: Query on new operator |
04 Sep 2006 06:50:39 AM |
|
|
Frederick Gotham wrote:
Jens Theisen posted:
"bharath.donnipad@gmail.com" <bharath.donnipad@gmail.com> writes:
int *intp = new int[2](7,17);
That's not standard C++. Maybe it's a microsoft extension.
Or perhaps the comma operator.
No, just a syntax error.
Best regards,
Tom
.
|
|
|
|
| User: "Ron Natalie" |
|
| Title: Re: Query on new operator |
04 Sep 2006 07:41:15 PM |
|
|
Frederick Gotham wrote:
Jens Theisen posted:
"bharath.donnipad@gmail.com" <bharath.donnipad@gmail.com> writes:
int *intp = new int[2](7,17);
That's not standard C++. Maybe it's a microsoft extension.
Or perhaps the comma operator.
Even
new int[2](17)
is invalid
.
|
|
|
|
| User: "Jens Theisen" |
|
| Title: Re: Query on new operator |
04 Sep 2006 03:00:08 AM |
|
|
Frederick Gotham wrote:
int *intp = new int[2](7,17);
That's not standard C++. Maybe it's a microsoft extension.
Or perhaps the comma operator.
So new int[2](17) is defined? What does it mean?
Jens
.
|
|
|
|
|
|

|
Related Articles |
|
|