C expert programming note 3

Source: Internet
Author: User

Chapter 3 C language statement analysis
Const int * grape;

Int const * grape;

Int * const grape;

In the last case, the pointer is read-only, and the above two pointers indicate that the object is read-only;

Struct can be used for field bits. I have never heard of it before:

[Cpp]
# Include <stdio. h>
Int main (){
Struct bit_field {
Unsigned int a: 1;
Unsigned int B: 4;
Unsigned int c: 8;
};
Struct bit_field temp;
Temp. a = 1;
Printf ("% d \ n", temp. );
 
Return 0;
}

If one line of code only does one thing, it looks simpler. For this reason, the declaration of variables should be separated from the declaration of types;
Some C-language books claim that "when calling a function, the parameters are pushed into the stack in the order from right to left". This is too simple-if you have a book like this, tear down the page and burn it. If you have such a compiler, delete the lines in the source code of the compiler. Parameters are first stored in registers as much as possible during transmission (for speed );

Integration has both advantages and disadvantages. Its determination is what the so-called advantages are actually not very good. The advantage of union is that it looks the same as the structure, but it replaces the keyword struct with the keyword union;

[Cpp]
# Include <stdio. h>
Int main (){
Enum sizes {small = 7, medium, large = 10, humungous };
 
Printf ("% d \ n", small );
Printf ("% d \ n", medium );
Printf ("% d \ n", large );
Printf ("% d \ n", humungous );
Return 0;
}

The usage of enumeration is roughly the same as above;
There are two types of big data: one is a parameter and the other is not a parameter.


From CodeBlog

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.