Summary of basic grammar of C/C++ language (1) End-of-term life-saving dry goods

  The basic grammar of the C language final exam, just read these few blog posts! (Dry goods one)

  Summary of C language final exam grammar:

   It must be clear in general:

   1) There are three types of program structures: sequence structure , selection structure (branch structure) , and loop structure .
   2) Read the program from the main() entry, and then from the top order to read down (when it encounters a loop, it is a loop, when it encounters a selection, it is selected), and there is only one main function .
   3) The computer saves data with binary numbers ; the data is stored in.
   4) bit means bit means 0 or 1; byte means byte, one byte = eight bits. Common test points for concepts:   1. Compilation preprocessing is not part of the C language and does not account for running time. Do not add a semicolon. The program compiled in C language is called the source program and is stored in a text file with ASCII values .   2. Define PI 3.1415926; This wording is wrong, semicolons must not appear.   3. There is one and only one main function in each C language program .   4. No more functions can be defined in the function .   5. Algorithm: There can be no input, but there must be an output.   6. Break can be used in loop structures and switch statements .   7. The comma operator has the lowest level , and the assignment number has the second lowest level.
  






  Chapter One Basic Knowledge of C Language

  The first section, the basic understanding of C language
  1. The program written in C language is called the source program, also known as the compiler unit.
  2. The C language writing format is free. You can write multiple sentences per line, and you can write multiple lines.
  3. A C language program has one and only one main function, which is the starting point of the program.
  Section 2. Compilers familiar with C/C++
  1. There are many compilers for C/C++. For example, VC and turbo C and CC compilers under Unix are all relatively old compilers. The blogger recommends that readers use Dev-C++ , VS and other relatively new IDE compilers, or directly use Vim+GCC/Clang+gdb in Linux (emcas editor is also available).
  2. After each C language program is written, it is compiled first, then linked, and finally run. (.C—.obj—.exe) During this process, note that the .c and .obj files cannot be run. Only the .exe file can run. (Of course this is only the case on the Windows operating system.)
   Section 3. Identifier
  1, Identifier (required content): The
  legal requirement is composed of letters , numbers , and underscores . Other elements are illegal.
And the first one must be a letter or an underscore , the first one is a number is illegal.
  2. Identifiers are divided into keywords, predefined identifiers, and user identifiers .

  Keywords: Cannot be used as user identification symbols. main define scanf printf are not keywords. Where it confuses you, If can be used as a user identifier. Because the first letter in If is capitalized, it is not a keyword.
  Pre-defined identifier: recite define scanf printf include. Remember that predefined identifiers can be used as user identifiers.

  Section 4: Conversion of hexadecimal system The
  decimal system is converted to binary, octal, and hexadecimal.
  Binary, octal, and hexadecimal are converted to decimal.
  Section 5: Integers and Real Numbers
  1) The C language only has eight, ten, and hexadecimals, but no binary. But at runtime, all hexadecimals must be converted to binary for processing.

    a、C语言中的八进制规定要以0开头。018的数值是非法的,八进制是没有8的,逢8进1。  
    b、C语言中的十六进制规定要以0x开头。

  2) The legal way to write decimals: If there is a zero on both sides of the decimal point in C language, you don't need to write it.

1.0在C语言中可写成1.
0.1在C语言中可以写成.1。

  3) Legal form of real data:

a、2.333e-1 就是合法的,且数据是2.333×10-1。
b、考试口诀:e前e后必有数,e后必为整数。请结合书上的例子。

  4) The integer type is generally 4 bytes, the character type is 1 byte, and the double precision is generally 8 bytes:

long int x; 表示x是长整型。
unsigned int x; 表示x是无符号整型。

  Sections 6 and 7: Arithmetic expressions and assignment expressions

  Core: The expression must have a value!

  1. Arithmetic expression: +, -, *, /,%

   考试一定要注意:
   “/” 两边都是整型的话,结果就是一个整型。 3/2的结果就是1. 
   “/” 如果有一边是小数,那么结果就是小数。 3/2.0的结果就是0.5
   “%”符号请一定要注意是余数,考试最容易算成了除号。)%符号两边要求是整数。不是整数就错了。[注意!!!]

  2. Assignment expression: the value of the expression is the leftmost value, a=b=5; the expression is 5, and constants cannot be assigned.

①、int x=y=10: 错啦,定义时,不可以连续赋值。
②、int x,y;
x=y=10;   对滴,定义完成后,可以连续赋值。
③、赋值的左边只能是一个变量。
④、int x=7.7;对滴,x就是7
⑤、float y=7;对滴,x就是7.0

  3. Compound assignment expression:

   int a=2;
   a*=2+3;运行完成后,a的值是10。
   一定要注意,首先要在2+3的上面打上括号。变成(2+3)再运算。

  4. Self-adding expression:

  自加、自减表达式:假设a=5,++a(是为6), a++(为6);
  运行的机理:++a 是先把变量的数值加上1,然后把得到的数值放到变量a中,然后再用这个++a表达式的数值6,而a++是先用该表达式的数值为5,然后再把a的数值加上1为6,
  再放到变量a中。 进行了++a和a++后 在下面的程序中再用到a的话都是变量a中的6了。
  Exam formula: ++ is used before, and ++ is used afterwards.

  5. Comma expression:

	优先级别最低。表达式的数值逗号最右边的那个表达式的数值。
(2,3,4)的表达式的数值就是4。
 z=(2,3,4)(整个是赋值表达式) 这个时候z的值为4。(有点难度哦!)
  z= { 2,3,4 }(整个是逗号表达式)这个时候z的值为2(部分编译器不会通过这种写法,即使部分	编译器通过编译,也会警告)。 

  Supplement:
  1. Empty statements cannot
be executed at will, which will cause logic errors .
  2. Comments are not part of C language code, do not account for running time, have no semicolons, and cannot be nested!
  3. Forced type conversion:

  一定是 (int)a 不是  int(a),注意类型上一定有括号的。
   注意(int)(a+b) 和(int)a+b 的区别。 前是把a+b转型,后是把a转型再加b。

  4. Three situations of rounding up and losing decimals:

       1、int a =1.6;
              2、(int)a;  
                3、1/2; 3/2;

  Section 8. Characters
  1) The legal form of character data:
   '1' means that the character occupies one byte, and "1" means that the character string occupies two bytes (including an end symbol).
   The ASCII value of '0' is 48, the ASCII value of'a' is 97, and the ASCII value of'A' is 65.
  The general test indicates the wrong form of a single character: '65' "1"  
  characters can be arithmetic operations, remember: '0'-0=48
  uppercase letters and lowercase letters conversion method:'A'+32='a 'There is generally a difference of 32 between each other.

  2) Escape characters:
  Escape characters are divided into general escape characters, octal escape characters, and hexadecimal escape characters.
  General escape character: recite \0, \n, \', \", \.
Octal escape character:'\141' is legal, leading 0 cannot be written, and every escape character in c The length is 1, the end of the string'\0' does not count as the length. The
  hexadecimal escape character:'\x6d' is legal, the leading 0 cannot be written, and x is lowercase.
  3. Character and integer Are close relatives: the two have great similarities
  4.

char a = 65 ; 
printf(“%c”, a);  得到的输出结果:a
printf(“%d”, A); 得到的输出结果:65                

Guess you like

Origin blog.csdn.net/qq_43515862/article/details/114191636