Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


the difference between new[] & new?

This topic is 6190 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

with the ''new'' operator, you allocate memory and get a pointer to it:

int* i = new int;

now, if you want to allocate an array of 100 int''s:

int* iv = new int [100];

(the size you allocate must be a constant/const variable)

..and make sure that you delete the second one like this:

delete [] iv; //delete the whole block

Share this post

Link to post
Share on other sites
new is for single items. For example:
// Gives you a pointer to 1 int
int* abc = new int;

new[] is for arrays. For example:
// Gives you a pointer to 10 ints
int* abc = new int[10];

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!