Detailed explanation of operators in c language 2

Table of contents

1: (conditional operator) ternary operator (expression1? expression2: expression3)        

 2: comma expression,

3: subscript reference, function call, structure member three operators

 4: Expression evaluation

5: Arithmetic conversion

1: (conditional operator) ternary operator (expression1? expression2: expression3)        

     1: Conditional operator (ternary operator)

        Its grammatical form is (expression 1? expression 2: expression 3) usage is:>

                If expression 1 is true, the value of the entire expression is expression 2, otherwise the value of the entire expression is expression 3

     Another way to understand is that if expression 1 is true, expression 2 will be executed, otherwise expression 3 will be executed. Here we give specific examples:>

           

 In fact, the ternary operator can actually be represented by an if...else statement, such as:

 2: comma expression,

Its syntax is that if a comma expression appears, the expression is executed from left to right, but the final result of the expression is the last value

Let's take two specific examples as examples:

This tells us that the final result of the comma expression is the result of the rightmost expression.

3: subscript reference, function call, structure member three operators

        1: The subscript reference operator [], this operator is often used when using arrays, and we have mentioned the specific examples before, so I won’t repeat them here, but one thing to note is that when using When using the reference operator, we must not use it out of bounds.

        2: The function call operator () is essentially represented by a pair of parentheses (), such as strlen ("abcd"), the parentheses here are the function call operator, and the operand of the function call, just put it The () can be removed, and the operand is strlen

with the string "abcd".

        3 Structure member operator. ->

        These two operators are used to refer to the members of the structure, and are often used when printing the structure.

        Grammar: Structure variable. Member name, let's introduce it through examples

        

The next step is the use of the -> operator. This operator is used by borrowing the structure pointer. The method of use is,

Structure pointer -> structure member, the following is explained through Liezi.

 4: Expression evaluation

        1: Implicit type conversion in expression evaluation: C's integer arithmetic operations are always performed with at least the precision of the default integral type. To achieve this precision, character and short integer operands in expressions are converted to normal integer types before use , this conversion is called integer promotion

        To put it simply, when our program is purely of character type and short integer type, our computer can at least only calculate the precision of the integer type, and the character type and short integer type will undergo integer promotion during calculation, but if the promotion is completed, if it is still If it is accepted by plastic, then plastic truncation will occur again:

//There are three storage methods for integers in memory, original code, complement code, and inverse code

 The plastic promotion of negative numbers, the sign bit is complemented in front, 1

Unsigned integer promotion, add 0 in front.

5: Arithmetic conversion

If the operands of an operator are of different types, the operation cannot proceed unless one of the operands is converted to the type of the other. The hierarchy below is called ordinary arithmetic conversions.

 Their relationship is:>

long double

double

float

unsigned long int

long int

unsigned int

int

 If the type of an operand ranks lower in the above list, the operation must first be converted to the type of the other operand.

                        

                        


                The sharing of this issue is over here, thank you for your patience in watching!

Supongo que te gusta

Origin blog.csdn.net/2201_75964502/article/details/130662034
Recomendado
Clasificación