"C + +" new and delete expressions

Source: Internet
Author: User

The new and delete expressions can be used to dynamically create and release individual objects, or to dynamically create and release dynamic arrays.
    When you define a variable, you must specify its data type and name. When you create an object dynamically, you only need to specify its data type, rather than naming the object. The new expression returns a pointer to the newly created object through which we access the object:
int i; Named, uninitizlized int variable
int *pi = new int; Pi points to dynamically allocated, unamed, uninitizlized int
This new expression creates a reshape object in the free store and initializes it with that address.
1. Dynamically created object initializationdynamically created objects can be initialized in a way that initializes variables:     
  
 
  1. int i(1024);
  2. int *pi = new int(1024);
  3. string s(10, ‘9‘);
  4. string *ps = new string(10,‘9‘);







From for notes (Wiz)

C + + new and delete expressions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.