C + + error R6030 CRT not initialized__c++

Source: Internet
Author: User

Yesterday, in writing an algorithm, the error R6030 CRT not initialized.

Careful examination found, is a relatively low-level error.

One

Error code, compile time will not error, the implementation of the report R6030 CRT not initialized:

Code One:

int *a= New int[];//This is not specified size

for (int i=0; i<ncount; i++)

{

Operate on A[i]

}


Delete[] a;//will complain.


Code two:

int *a= New int;//actually allocates an int memory.

for (int i=0; i<ncount; i++)

{

Operate on A[i]

}

Delete[] a;//will complain.


After these 2 treatments, a[] can achieve the effect you want, such as sorting.

However, when exiting, the R6030 CRT not initialized is reported.


Second, theoretical knowledge:

A >new usage:

1. Open a single variable address space
1) New int; Opens up a storage space for the array and returns an address to that storage space.
int *a = new int assigns the address of an int type to integer pointer a.
2 int *a = new int (5) acts as above, but at the same time assigns an integer value of 5
2. Open array Space
One-dimensional: int *a = new INT[100]; Create an integer array space of size 100
Two-dimensional: int **a = new Int*[5]
for ()
{A[i] = new int[6];}
Three-dimensional and above: and so forth.
General usage: new type [initial value]
Delete usage:
1. int *a = new int;
Delete A; Free space for a single int
2.int *a = new Int[5];
delete [] A; Frees int array space

To access the structure space opened by new, you cannot go directly through the variable name, only through the assigned pointer.
Use new and delete to dynamically open up and undo the address space. If you run out of a variable (typically a temporarily stored array) at the time of the program,
The next time you need to reuse, but you want to save the initialization of the Kungfu, you can start each time to open a space, after the use of the undo it.

Be sure to know N, M before you can assign.


Third, the correct code

int *a= New int[n];//here must find a way to know the size of N.

for (int i=0; i<ncount; i++)

{

Operate on A[i]

}

Delete[] a;//and new[] correspond.

A=null;


Reprint please indicate original link: http://blog.csdn.net/wujunokay/article/details/12041699




Related Article

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.