Take notes (operators) on the third day of IOS learning, and take notes on the third day of ios learning.

Source: Internet
Author: User
Tags integer division

Take notes (operators) on the third day of IOS learning, and take notes on the third day of ios learning.

IOS Learning (C Language) knowledge point sorting notes

1. Operators

I. Arithmetic Operators

1) An expression is composed of variables, constants, and operators. It has a definite type and value.

2) Arithmetic Operators include: + (plus),-(minus), * (multiplication),/(Division), % (Modulo)

3) Arithmetic Operator priority brackets ()> *,/, %> + ,-

4) % indicates taking the remainder, modulo a % B indicates dividing a by B and taking the remainder

5) The Integer Division retains two decimal places for processing, such as: printf ("%. 2f", (float) 14/9 );

6) Auto-increment and auto-increment operators: ++ ;--

7) differences between a ++ and ++ a: ++ a returns a + 1 and B = ++ a, which is equivalent to a = a + 1 and B =; a ++ returns a, B = a ++ equivalent to B = a and then a = a + 1

 

Ii. Relational operators

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

2) The result of Comparison Between Relational operators is 1 (true) and 0 (false)

 

Iii. logical operators

1) logical operators include:

& (Logic and/, and it takes two of them to be true );

| (Logical or/or true if one condition is met );

! (Logical non-/Not )! (True) = false! (False) = true non-0 = true logical operators are generally used with if

 

4. Three-object Operator

1) Structure of the Three-object operation: (conditional expression )? (Statement 1): (Statement 2)

Example: c = a> B? A: B; indicates that the maximum value of a B is assigned to c.

 

V. assignment operators

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

2) + = indicates that the former variable is equal to the original value of the variable plus the following values, for example, a + = B Indicates a = a + B;

 

Vi. Comma Operator

1) the comma operator has the lowest priority, for example (expression 1, expression 2,..., expression n) = expression n obtains the last expression.

7. bitwise (single bit) Operator

1) bitwise AND &; bitwise OR |; bitwise inversion ~ ; Displacement operation

2) For example:

    

1 int a = 0xff; 2 printf ("% d \ n", a & 0x0f) // The result is: 0x0f = 15 3/* 4 analysis: 5 1111,1111 6 then, 1111 7 ---------- 8 then, 1111 (0 indicates that false 1 is true & false under conditions & True = true) 9 */10 11 a = 0xf0; 12 printf ("% d \ n", a | 0x0f); // 0xff13/* 14 1111,000015 bytes, 111116 */17 18/* set the third bit Of a to 0, start from bit */19 a = 0xcc; // 0b1100110020 a = a & 0xf7; 21/* 1100,110022 1111,0111 // 0b1100, 0100 0xc4 = 19623 */24 25/* 26 set the third bit Of a to 127 */28 a = 0; 29 a = a | 0x8; 30 /* 31 bytes, listen 32 bytes, 1000 = 0x8; 33 */34 printf ("a = % d \ n", a); 36 a = 0b110; 37 printf ("% d \ n", a <2); // 0b1, 1000 = 2439 a = 0b0110; 40/* 41 analysis: 42 int = 4 bytes = 32bit 43 that is, a = 0b0110 = 0b random, 0000, random, 0000, random, 011044 results after bitwise inversion: 111111,1111, 1111,1111, 111111,1111,111111111111, 1111,100 */46 printf ("~ A = 0x % x = % d \ n ",~ A ,~ A); // bitwise inversion, 0xfffffff9 =-7

 

 

8. Comparison of priorities of Operators

Brackets (nested)> single object (++,-,!)> Arithmetic> relationship> logic> value assignment

 

9. Data Type Conversion

1 int main () 2 {5 int a = 0xfff1;
7 char c = a; // implicit conversion
9 printf ("% d = 0x % x \ n", c, c); // truncation, low 8 bits11 printf ("% f \ n", (float) 14/5); // forced type conversion, 14 converted to float13/* 15 1, and long, converted to long17 2, float involved in the calculation, convert to double 19 3, char and short, convert to int21 4, signed-> unsigned 23 */25 float f = 3.14; 27 printf ("3.14 + 2000 = % f \ n", f + 2000); 29 char records =-128; // 0x8031 int I = bytes; // char-> int. bit Extension: Add 1 to a negative number, and add 033 to a positive number. // 0x80 (char)-> 0 xffff, ff8035 printf ("I = % d = 0x % x \ n ", i, I); 37 bytes = 8; // 0x839 I = bytes; // char-> int. bit Extension: Add 1 to a negative number, and add 041 to printf ("I = % d = 0x % x \ n", I, I); 43 return 0; 45}

 

10. macro definition

1) macro definitions are generally in uppercase format: # define alias (uppercase) Expressions/parameters

2) The role of macro definition is to make code readable and easy to modify.

3) For example, the macro-defined method is used to calculate the maximum two numbers:

1 # define MAX (a, B) a> B? A: b2 # include <stdio. h> 3 int main () {4 printf ("enter two numbers: \ n"); 5 scanf ("% d", & a, & B ); 6 printf ("maximum value: % d", MAX (a, B); 7 return 0; 8}

 

11. Input and Output

1) scanf ()/getchar () is used to receive user input printf ()/putchar () for output information.

2) scanf ("formatted string", parameter address list) scanf input parameters must be added with "&" to get the address symbol scanf according to the Return key,

Separate characters by Tab space. Press enter to indicate that the receiving is complete. scanf can also specify the length of the received input. If the input information is greater than the specified length

It is intercepted from the right to the left. For example: int a = 12345; scanf ("% 3d", & a) printf ("% d", a) the output result is 123; low input information

The specified width is not affected.

3) printf ("Format String", output information); In printf, you can set the output width by adding a number to the format string;

For example, printf ("% 8d", 19) changes to the right and outputs 19 characters in length. If the output data is greater than the specified width, it does not work.

4) solve the scanf input buffer problem: when there is an input before the input is char (% c) type, the input will be skipped directly.

For example:

1 short s; 2 3 printf ("enter a Short \ n"); 4 5 scanf ("% hd", & s ); 6 7 printf ("output a Short Value % hd \ n", s); 8 9 char c, last; 10 11 printf ("input a char \ n "); 12 13 scanf ("% c", & c); // method 1 residual a carriage return character % c in the input buffer as the valid input 14 15 // last = getchar (); // method 2 getchar () removes a character 16 17 scanf ("% c", & c); 18 19 printf ("output a char Value % c \ n ", c );

 

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.