Defining constants
Divided into three parts: data type variable name = initial value
Defining integer variables
Naming rules for variable names:
1. Variable names can only consist of numbers, letters, underscores, and numbers cannot begin.
2. Cannot duplicate the system keyword.
3. With self-explanatory, see the name of the meaning.
4. Variable names cannot be duplicated.
5. When a variable name consists of more than one word, the first letter of the first letter of the word is capitalized.
int a = 10; Float B = 1.0;//is used to annotate a row. char a = ' a ';
Used to comment a row
/* * To comment on a paragraph
//practice 1: int a = 10; int b = 5; int c = 0; int a = 10, b = 5, c = 0; //the process of assigning a value is a copy of the process. c = a;//c 10,a 10,b 5 a = b ;//c 10,a 5, b 5 b = c;//c 10,a 5, b 10 int maxage = 10;
//arithmetic operator float a = 0; a = 3.0 / 5; //division operation, Divisor cannot be zero. printf ("%f", a); int a = 10; int b = 3; int c = 0; c = a + b; printf ("%d\n", c); // \n line break. c = a - b; printf ("%d\n", c); c = a * b; printf ("%d\n", c); c = a / b; printf ("%d\n", c); c = a % b; printf ("%d\n", c);
+ +, self-increment 1,--, self-minus 1;
+ +,--in front of the variable, perform the ++,--operation first, then participate in the operation.
+ +,--at the back of the variable, first participate in the operation, then + +,--。
c = a++; c = A; A = a + 1; c = ++a; A = a + 1; c = A; c = a--; A = A-1; c = A; c = a+++b; c = a++ + B; Combine as much as possible into the largest computational unit. printf ("%d,%d,%d\n", C, a, b);
Conforming operator, +=,-=,*=,/=,%=
You cannot add spaces to the middle of a conforming operator.
c + = b; c = c + B; c =-6%-4; Both ends of the take-out operator must be integers. printf ("%d\n", c);
Basic output functions
%d integer (integer)%f floating-point (decimal)%c character type%ld long integer
int name = 10; printf ("%d", name); printf ("\ \"); int d = 0;
Format input function scanf ("%d", &d); Input operation, you need to get the variable address. printf ("%d", d); int a = 0; int b = 0; int c = 0; Enter the value of a, b from the console. scanf ("%d%d", &a, &b); printf ("%d,%d", A, b); float a = 10.2; printf ("%.2f", a); %.2F represents two digits after the decimal point
/* Job 1: printf (" * \n"); printf (" * * \n"); printf ("* * *\n"); */ /* Job 2: float a = 0.00;  SCANF ("%f", &a); a = a * 0.05 + a; printf ("%.2f\n", a); */ /* Job 3: int a = 0; int b0 = 0; int b1 = 0; int b2 = 0; int b3 = 0; int b4 = 0;    INT C = 0;    SCANF ("%d", &a); b1 = a / 20; c = a % 20 ; b2 = c / 10; c = c % 10; b3 = c / 5; c = c % 5; b4 = c / 1; b0 = b1 + b2 + b3 + b4; printf ("%d,%d,%d,%d,%d\n",  B1, B2, B3, B4,  B0); */ /* Job 4: int a; int  B;    SCANF ("%d%d", &a, &b); printf ("%d\n",  A + B); printf ("%d\n", a - b); printf ("%d\n", a * b); printf ("%d\n", a % b); */
This article is from "iOS Growing Up" blog, declined reprint!