0 length array meaning

Source: Internet
Author: User

In the _c++ primer_ dynamic array, it is legal to allocate an empty array dynamically.

size_t n = get_size();int* p = new int[n];for(int* q = p; q != p + n; ++q)char arr[0];//错误char cp = new char[0];

When we use new to allocate an array of size 0, new returns a valid non-null pointer. This pointer is guaranteed to be different from any other pointers returned by new, and for arrays of length 0, this pointer is like a trailing pointer. We can use this pointer like a post-tail iterator.

Chenhao Blog C language structure in the member array and pointers, refers to the 0-length array meaning.

A 0-long array at the end of a structure, such as a char bytes[0], that indicates that the structure is indefinite and can be extended by means of an array. The structure must contain a length information. The structure itself resembles an information header. At the same time, this structure can only allocate memory by heap.

Reference

[1].http://blog.csdn.net/wade23/article/details/4510971

[2].http://coolshell.cn/articles/11377.html

0 length array meaning

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.