0X02 C language overview, 0x02 Overview

Source: Internet
Author: User

0X02 C language overview, 0x02 Overview

A c program consists of one or more functions and must have only one main () function. I recommend that you do not use the void main format. We recommend that you use the int main and return 0; format. I do not know why I want to do this.

A code block can be called within a file, within a function, within a control statement, or in a pair of curly brackets.

Declaration and definition

Int num; this is the declaration, and it is the definition declaration.

Statement(Declaration) specifies a variable identifier to describe the type, type, object, or function of the variable.

Definition(Defining) is the implementation or instantiation of the Declaration.

There are two types of declarations: bucket creation and bucket creation. The former is a definition declaration, and the latter is a referncing declaration)

In a broad sense, declarations include definitions, but not all declarations are definitions. Generally, the bucket creation declaration is called "definition", and the bucket does not need to be created as "declaration"

Not quite clear yet? It doesn't matter. You just need to know that the definition is not the same as the declaration.

In C, all variables must be defined before use.

The function prototype is a declaration form.

Benefits of declaring variables:
  • Putting all the variables together makes it easier for readers to understand the program content (if the name cannot be clearly expressed, you can use annotations to explain it. This is also a good Programming Technique)
  • Before you start programming, consider the variables that need to be declared to encourage you to do some planning work.
  • It can help avoid spelling errors of variable names. For example, if an error is written in the code below, the compiler will help you find the error.
Program readability skills
  • Select meaningful variable names and comments
  • Use empty rows to separate multiple conceptual parts of a function. For example, separate the definition part and action part.
  • Each statement uses one row, except for those in parentheses of the for loop.
  • Use annotations at the beginning of the program to describe the name of the file and the purpose of the program.
Debugging

Syntax error: indicates that the correct C symbol is placed in the wrong position.

Another problem with the compiler is that the location where the error is found lags behind the location where the real error is located.

Semantic Error: indicates an error. The syntax is correct, but the output result is not desired. Generally, a semantic error occurs in the code.

Adding additional printf statements to the key points of the program to monitor the value of the selected variable can help you find semantic errors.

 

Program Status: manually track the program step by step and record each variable to monitor the program status.

You can also use a debugger to check the program status, including static debugging and dynamic debugging.

 

;

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.