Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C - C++ Learning > Re: Allocating ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 8 Topic 4126 of 4302
Post > Topic >>

Re: Allocating memory with "new"

by barss <barss.dev@[EMAIL PROTECTED] > Apr 24, 2008 at 03:19 AM

On Apr 23, 8:00 pm, "sk_usenet" <sometechyguy at gmail dot com> wrote:
> "Pat" <pkelecy@[EMAIL PROTECTED]
> wrote in message
> >I have a question about the new operator.  The syntax for it is:
>
> > int * pointer = new int;
>
> > which says that "pointer" points to a type int variable.
>
> > My question is why is "int" needed twice?  I know it's needed from a
> > syntax standpoint, but I don't understand what additional information
the
> > second int really provides.  Doesn't the first int already tell you
that
> > an int type value is going to be stored at the "pointer" address?
>
> What about arrays?
>  int *p = new int[10];
>
> > Can you ever have,
>
> > int * pointer = new double
>
> No, realize that new operator is returning a double*, and heance trying
to
> assign to an int* is not legal.
>
> > or something like that?
> > Thanks for any feedback on this.
>
> --http://techytalk.googlepages.com

never mind. You use "int" to store pointer. This trick will be work
for 32 bit platforms because size of any pointer will be 4 bytes. But
for 64 bit platforms you will have a problem, because size of any
pointer will be more than 4 bytes. You can see note also about pointer
to int conversion when compiling.
 




 8 Posts in Topic:
Allocating memory with "new"
Pat <pkelecy@[EMAIL PR  2008-04-23 07:40:12 
Re: Allocating memory with "new"
Francis Glassborow <fr  2008-04-23 13:48:37 
Re: Allocating memory with "new"
pat <pkelecy@[EMAIL PR  2008-04-23 18:52:39 
Re: Allocating memory with "new"
"sk_usenet" <  2008-04-23 10:00:56 
Re: Allocating memory with "new"
pat <pkelecy@[EMAIL PR  2008-04-23 18:55:25 
Re: Allocating memory with "new"
barss <barss.dev@[EMAI  2008-04-24 03:19:49 
Re: Allocating memory with "new"
Francis Glassborow <fr  2008-04-24 11:38:30 
Re: Allocating memory with "new"
Ulrich Eckhardt <dooms  2008-04-26 08:11:08 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 13 4:30:33 CDT 2008.