Introduction to C language (2) Statements and operators

Source: Internet
Author: User
Tags exit in

Introduction to C language (2) Statements and operators

The basic statements in C language are similar to those in Java.

  • Loop statements (do while, while,)
  • Conditional statements (if, if-else, switch)
  • Goto statement (for example, defining an Exit mark outside the loop:; you can use goto Exit in the loop; jumping out of the loop)

     

    [Plain] 
    1. For (int I = 0; I <5; I ++)
    2. {
    3. If (I = 2) goto exit;
    4. Printf (I = % d, I );
    5. }
    6. Exit :;
    7. Printf (admin );

       

      Arithmetic Operators

      • + Addition Operators
        • -Subtraction operator or negative operator
          • * Multiplication Operator
            • /Division Operator
              • % Modulo operator, or the remainder operator, must be an integer on both sides of %

                 

                Relational operators

                • <Less than Operator
                  • <= Less than or equal to the operator
                    • > Greater than Operator
                      • > = Operator greater than or equal
                        • = Equals Operator
                          • ! = Not equal to operator

                             

                            No boolean type in C Language

                            In C language, if the result of the relational operation is true, 1 is returned. If false, 0 is returned.

                            Int a1 = 5> 4; // 1

                             

                            Int a2 = 5 <4; // 0

                            * Note that in C, any non-0 value is true. Only 0 value is assumed as if (-1 ){}

                            If (a = 0 ){}

                            In the C language, you can save the result of the relational operation. Therefore, the following statement is valid:

                            Int a = 10;

                            A> 10;

                            A = 0;

                             

                            Logical operators

                            • & Logic and operators
                              • | Logic or operator
                                • ! Logical non-Operator

                                  There are only two results for the logical operation: true if it is true, 1 is returned; false if it is not true, 0 is returned.

                                  Compound assignment operator

                                  • + = Add the value assignment operator. For example, a + = 3 + 1 is equivalent to a = a + (3 + 1)
                                    • -= Minus value assignment operator. For example, a-= 3 + 1 is equivalent to a = a-(3 + 1)
                                      • * = Multiplication and value assignment operator. For example, a * = 3 + 1 is equivalent to a = a * (3 + 1)
                                        • /= Except the value assignment operator. For example, a/= 3 + 1 is equivalent to a = a/(3 + 1)
                                          • % = The remainder assignment operator. For example, a % = 3 + 1 is equivalent to a = a % (3 + 1)

                                            Auto-increment and auto-increment Operators

                                            • ++ Auto-increment operator. For example, a ++ and ++ a are equivalent to a = a + 1.
                                              • -- Auto-subtraction operator. Such as a --, -- a, are equivalent to a = A-1

                                                Comma operator and comma expression

                                                * The comma operator is mainly used to connect expressions, such:

                                                Int a = 9;

                                                Int B = 10;

                                                A = a + 1, B = 3*4;

                                                The operation procedure of the comma expression is: from left to right, first calculate expression 1, then calculate expression 2,..., and finally calculate expression n

                                                * The value of the entire comma expression is the value of the last expression c = (++ a, a * = 2, B = a * 5); <==> c = B;

                                                Operator: int a = (B> 5 )? 10: 9;

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.