The operation and flow control of the Dark Horse programmer----C language

Source: Internet
Author: User

operation and flow control of C language   First, the operation part:   type conversion in C language Forcing type conversionsint b = (int) 10.5 //Double int

Automatic type conversion

int a = 10.6 //Double int       

int B = 10.5 + 1.7 //Automatic large conversion to decimal type, loss of precision

Automatic type promotion

int b = 10.5 +10; //INT--double-lift the right 10 to the double type to resolve

double b =3.0/2; //Solve the precision problem of division or double b = (double) 3/2;    

1 sizeof     (ten); //calculation of bytes/storage space 2 3 sizeof      ten; // can be without parentheses 4 5 sizeof     (a); // You can use the variable name 6 7 sizeof  (double);  // computes the number of bytes of type double               

Relational operations in C language

Not 0 is true, only 0 is false.

Also called the comparison operation

Commonly used are: > < >= <= = = =!

Logical operations in C language

Logic and condition a && condition B //AB at the same time set up as true

Logic or condition A | | Condition b //AB as long as there is a set up is true

Logical Non! Conditions //True or false false is true

Three-mesh operations in C language

Conditions? Value A: Value b //condition is set to return a, not set to return B

Second, the Process Control part

Process control is divided into sequential structure, selection structure and cyclic structure.

The selection structure in C language

Select Structure IF

if (expression) the first structure

Statement 1;

if (expression) second structure

Statement 1;

Else

Statement 2;

if (expression) third structure

{

Statement 1;

}

If the fourth kind of structure

else if

Else

Select Structure Switch

switch (expression/value)

{

Case value 1;

Statement 1;

Break ; //exit the entire switch statement

Case value 2;

Statement 2;

Break

Defauletl;

Statement 3;

Break

}

Loop structure while

1       while (condition) 2 3    {  45      loop body // is set to execute only once, not set up never execute 67    }  89     dead loop:while (1);              

 

Loop structure Do While

1  Do {  23          // execute one at a time before judging 4 5         }  while (conditions);        

Loop structure for

1   for (statement 1; condition; statement 2) 2 3     {  45        loop body                              67    }  8  9for     (,,)            

Break and Continue

Break

Exit the entire switch statement or exit the entire loop statement

Continue

End the current loop body and enter the next loop body

loop structure and operations in the C language is a very important part, especially the loop structure, in a lot of places can come in handy, so must be the circular structure study understand, the research is thorough, so as to avoid some small mistakes in the future.

The operation and flow control of the Dark Horse programmer----C language

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.