iOS Phase Learning Third Day notes (operator)

Source: Internet
Author: User

iOS learning (c language) knowledge points to organize notes

1. Operators

First, arithmetic operators

1) expressions are composed of variables, constants, and operators, with deterministic types and values

2) arithmetic operators include: + (plus),-(minus), * (multiply),/(except),% (modulo)

3) arithmetic operator precedence brackets () > *,/,% >+,-

4)% means take-up, modulo a%b means a divided by B to take the remainder

5) Integer division reserved Two decimal places processing methods such as: printf ("%.2f", (float) 14/9);

6) Self-increment decrement operator: ++;--

7) The difference between a++ and ++a: ++a return value is a+1, B=++a equals a=a+1 then b=a; The a++ return value is a, b=a++ equals b=a and then a=a+1

Second, relational operators

1) Relational operators include:, >=, <, <=, = =,! =

2) The relational operator comparison result is 1 (true), the result is 0 (false)

Third, logical operators

1) logical operators include:

&& (Logic and/and 2 are set up to be true);

     || (logic or/or as long as a condition satisfies is true);

      ! (Logical not/not)! (true) = False! (false) = true non-0 = True logical operator generally with if

Four or three mesh operator

1) Three mesh operation composition: (conditional expression)? (statement 1):(Statement 2)

Example: c= a>b?a:b; Represents the maximum value of a B in both assignments to C

Five, assignment operators

1) Assignment operators include: =,+=,-=,*=,/=,%=

2) + = Indicates that the former variable equals the value of the variable plus the following value for example: A+=b represents a=a+b;

Six, comma operator

1) The comma operator has the lowest precedence for example (expression 1, expression 2, ..., expression n) = Expression n takes the last expression

 

Seven, bit (single bit) operator operators

1) Bitwise and &, bitwise OR | ; bitwise counter ~; Displacement operation

2) For example:

     

    

1 intA=0xFF;2printf ("%d\n",a&0x0f)//The result is: 0x0f=153 /*4 Analysis:5 1111,11116 0000,11117 ——————————8 0000,1111 (0 false 1 is True & false & true = Add true & true = True)9 */Ten OneA =0xf0; Aprintf"%d\n"+a[0x0f);//0xFF - /* - 1111,0000 the 0000,1111 - */ - - /*set the third bit of a to 0, from the first bit*/ +A =0XCC;//0b11001100 -A = a&0xf7; + /*1100,1100 A 1111,0111//0b1100,0100 0xc4=196 at */ - - /* - set the third bit of a to 1 - */ -A =0; inA = a|0x8; - /* to 0000,0000 + 0000,1000 =0x8; - */ theprintf"a=%d\n", a); $A =0b110;Panax Notoginsengprintf"%d\n",a<<2);//0b1,1000=24 theA =0b0110; + /* A Analysis: the int=4 bytes =32bit + namely a=0b0110=0b 0000,0000,0000,0000,0000,0000,0000,0110 - results after bitwise inversion: 1111,1111,1111,1111,1111,1111,1111, 1001 $ */ $printf"~a=0x%x=%d\n", ~a,~a);//Bitwise Inversion, 0xfffffff9=-7

Viii. precedence comparisons of operators of various types

brackets (can be nested) > monocular (+ +,--,!) > Arithmetic > Relationships > Logic > Assignment

IX. Conversion of data types

1 intMain ()2 {5    intA =0xfff1;
7 Char C = A; // Implicit conversions
9printf"%d=0x%x\n", c,c);//truncate, take 8bits lower Oneprintf"%f\n",(float) -/5);//forced type conversion, 14 turn into float - /* the 1, and long operation, turn into a long - 2. Float participates in the operation and turns into a double operation + 3, Char and short operations, turn int + 4. Unsigned without symbols at */ - floatf =3.14; -printf"3.14+2000=%f\n", f+ -); in CharCH1 =- -;//0x80 to inti = CH1;//char->int. bit extension: Negative complement 1, positive complement 0 - //0x80 (char), 0xffff,ff80 *printf"i=%d=0x%x\n", i,i);Panax NotoginsengCH1 =8;//0x8 thei = CH1;//char->int. bit extension: Negative complement 1, positive complement 0 Aprintf"i=%d=0x%x\n", i,i); + return 0; $}

X. DEFINITION of macro

1) Macro definitions are generally uppercase: #define ALIAS (uppercase) expressions/Parameters

2) The function of macro definition is how to make the code readable and easy to modify

3) For example, a macro definition is used to calculate the maximum value of two:

  

1   #define MAX (A, b) a>b?a:b2   #include <stdio.h>3    int  main () {4         printf ("Please enter two number: \ n"); 5         scanf ("%d%d",&a,&b); 6         printf ("Maximum is:%D", Max (A, b)); 7         return 0 ; 8    }

iOS Phase Learning Third Day notes (operator)

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.