Article 1 --------- some basic and fragmented knowledge of the c language, --------- c

Source: Internet
Author: User

Article 1 --------- some basic and fragmented knowledge of the c language, --------- c

First, my blog address is ghost!

C language is a classic language, so I will not talk about it more here. Let's discuss it from the basics!

I. defines an integer. If it is used as a local variable and is not initialized, It is a random value. In general, the output is 0, but this 0 is used as the garbage value; if the global variable is not initialized, its value is 0.

II. we all know that static is used to declare an internal global variable. When static is used, it will not re-open a bucket in the memory, so its superiority is time to play a role, if the call frequency of a method is very high, and the write variable value in the method is fixed, if we use static to modify the variable, this variable can only open up the storage space once, and improve the efficiency and performance of the program during the running process.

III. macro definition with parameters. if we use a macro definition with parameters to perform some simple operations, a small amount of code may not show its superiority, but in thousands of lines of code, it can improve the performance of the entire software program! For example, in a simple example, int a = 10; int B = 20; the calculation result can be int res = a + B; the macro definition should be like this: outside the main function, # define SUM (v1, v2) (v1 + v2) directly implements int res = SUM (a, B) in the main function. It seems that there is no difference, according to the operating principle, the macro definition allows the program to directly obtain the (10 + 20) operation, instead of using the macro definition, we need to assign values to a and B before the operation, it is a "detour" step by step.

4. when we mention macros, we should think of some details in typedef, define, and typedef. Some friends may not notice that if we want to give the pointer type variable "alias ", what "unexpected" will happen when define is used? Well, let me start with a # defiine MY_STRING char *. In the main function, call MY_STRING name1 and name2. What are the consequences? The result tells you that there will be bugs. the reason is that MY_STRING name1, name2 ==== char * name1; char name2; in my personal opinion, name2 "cannot eat *" is used as a pointer variable, if not, an error is returned!

Okay! It's not too early. You can write something when you have time to think about it! I hope you will be grateful for the shortcomings!

 

 

 

 

 

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.