当前位置:网站首页>Preliminary understanding of C program design

Preliminary understanding of C program design

2022-07-03 21:13:00 Can't learn java

1、 ordinary C Program

1.1、C Program Introduction

#include <stdio.h> // Compile preprocessing commands 
int main(){
    			// The main function 
	printf("HelloWorld");
	return 0;
}
  • One C Procedure by function form , function It's the composition C programmatic Basic unit , sentence It's the composition C The smallest unit of a program .
  • One C The program always consists of The main function Start execution .
  • One line can write one or more statements , A statement can also be written on one or more lines .
  • It is better to add ; end .

2、C Language indicator , Constants and variables

  • The composition of the identifier :

    1. Identifier is created by Numbers 、 Letter 、 Underline form
    2. It can only start with Letters or underscores
  • Classification of identifiers :

    Be careful :
    1、 Keywords cannot Used as user identifier
    2、 keyword
    All in lowercase
    Letter
    3、 identifier Case sensitive
    4、 Predefined identifiers can Used as user identifier

    1. User identifier
    2. Predefined identifiers :
      scanf( Input function )、pringf( Output function )
      include( File contains )、define( Macro definition )
    3. keyword :32 individual

2.1、 Constant

  • Common basic data types include integer 、 Real type 、 Character .
  • Constant : Its value during program operation It can't be changed The amount of .

2.2、 Variable

  • Variable : While the program is running , Its value You can change The amount of .
  • Variable name : from identifier form .
  • Unassigned variables default to random values .

3、 Integer data

Integer data is stored in the form of complement
%d --> Decimal format output
%o --> Output in octal format ( Without the lead )
%x --> Hex format output ( Without the lead , The output format depends on the case %x Case write )

3.1、 integer constants

  1. Decimal system
  2. octal : Leading 0(0123)
  3. Hexadecimal : Leading 0x or 0X(0X10)
  4. C There is no binary data in the language

3.2、 Integer variables

int Basic type TC2 Bytes /VC4 Bytes
short Short 2 Bytes
long Long integer 4 Bytes
unigned No sign

4、 Real data

%f Output format : Default hold 6 Decimal place , Insufficient 6 Place zero , More than rounding

4.1、 Real constant

  • Decimal form : from Numbers 、 The sign 、 decimal point form
    • The rules of composition :
      1. There has to be decimal point
      2. decimal point At least there are numbers on one side
  • Exponential form : from E or e form
    • The rules of composition :
      1. Numbers on both sides
      2. Index part It has to be an integer (E/e The right is an integer )

4.2、 Real variable

Single precision float4 Bytes
Double precision double8 Bytes

5、 Character data

5.1、 character constants

Legal character constants : Enclose one character in single quotation marks

  • Regular character constants : A character wrapped in single quotation marks ‘a’ ‘W’ ‘c’ ‘F’
  • Escape character constants (6+2 Six basic + Two extensions )
    1. ‘\n’ —— Carriage returns (Enter)
    2. ‘\t’ —— Skip horizontally (Tab)
    3. ‘\b’ —— Backspace (BackSpace)
    4. ‘\\’ —— The backslash
    5. ‘\’’ —— Single quotation marks
    6. ‘\"’ —— Double quotes
    7. ‘\ddd’:1 to 3 position 8、 ... and Decimal integer 1 individual character
    8. ‘\xhh’:1 to 2 position sixteen Decimal integer 1 individual character
  • String constant : Characters wrapped in double quotation marks , End mark ’\0’

5.2、 Character variables

  • char: Occupy 1 Bytes

6、 Arithmetic expressions

6.1、 Basic operators

  • +、-、*、/、%

    a/b

    • if a And b They are all integers , The result is an integer
    • if a And b Any one of them is real , The result is real
  • %( Seeking remainder ): Can only be used for integer
    1. Remainder Plus or minus Depending on Divisor (% On the left )

6.2、 Precedence and associativity of operators

  • priority : order
    () > +( Correct )、-( Take the negative ) > *、/、% > +( Add )、-( reduce )
  • associativity : Direction

6.3、 Cast cast character

  • form :( Type name ) expression
  • evaluation :
    1. (int)2.2 == 2
    2. (int)5.5/(int)2.5 == 2
    3. (int)5.5+2.5 == 7.5

7、 Assignment expression

7.1、 Assignment operator

  • form : Variable name = expression
  • priority : Only higher than the comma operator
  • associativity : From right to left

7.2、 Compound assignment operator

  • +=、-=、*=、/=、%=
  • priority : Only higher than the comma operator
  • associativity : From right to left

8、 Self addition and self subtraction and comma operators

8.1、 Self addition and self subtraction operators

  • form : ++ Variable 、- - Variable 、 Variable ++、 Variable - -
  • Be careful : The operation object of self addition and self subtraction must be Variable
  • Pre value usage :++i or - -i
    • First, change the variable i The value of the add 1 Or minus 1, And then use i Value .( Change immediately , Use new value )
  • Post value usage :i++ or i- -
    • Use variables first i Value , And then you put the variables i The value of the add 1 Or minus 1.( Use the old value first , Change again )
  • summary :
    Variable expression Variable
    i=2++i==3i==3
    i=2- -i==1i==1
    i=2i++==2i==3
    i=2i- -==2i==1

8.2、 The comma operator

  • form : expression 1, expression 2,···, expression n
  • priority : The minimum
  • associativity : From left to right

    Evaluate from left to right , take expression n As the value of the entire comma expression

原网站

版权声明
本文为[Can't learn java]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/184/202207032102105513.html