What's new in c99c

Source: Internet
Author: User

Following the previous composite text, today we continue to talk about the new features of c99c.

The C99 standard is the second official C-language standard following the C89 standard, which was officially released on December 1, 1999, with an increase in the number of data types (added to the _bool), and the addition of keywords (adding the inline restrict keyword), which undoubtedly brought many conveniences to our programming.

1. Specify the initialization character

The specified initializer is typically used in two ways: for arrays and for structs and unions

(1) for arrays

Format used for arrays: [Index] = vol; where index represents the subscript of the Array, and vol represents the initialization value of this array element. For example:

int x[] = {[0, [5]// where x[5],x[10] has been initialized 

(2) for structures and unions

The format used for structs or unions is as follows:Member-name (member name), which allows a simple method to initialize a specified member of a struct when a struct is specified for initialization. For example:

struct int Object  Ten ;  

Note: There is no limit to the order in which struct members are initialized.

2. Telescopic array

Another exciting feature of c99c is the telescopic array, which is used in structs. This attribute declares that the last member is an array with a special attribute. The envoy attribute has two points, 1. This array does not exist, at least not immediately. 2. We can write code that uses the array member appropriately, just as it does and has any number of elements you need. It sounds strange, let's look at some examples:

struct flex{  int  count;   Double average;   Double score[];};

Some usage rules for telescopic arrays:

(1) A telescopic array member must be the last array member.        (2) There must be at least one other member in the structure. (3) The telescopic array is declared just like an ordinary array, except that his square brackets are empty.
structmalloc(sizeof(struct5*sizeof(double) ); // now we have enough memory to store count,average and 5 arrays of double values. You can use PTR to access their classes:5;p tr->score[212.3;

This allows you to modify the size of the structure to occupy space at any time.

What's new in c99c

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.