[C++ Advanced] Chapter 1: [C Language Basics] C Language Overview and Data Types

Table of contents

1. Overview of C language 

(1) Computer structure composition

(2) Computer system composition 

(3) ASCII code

(4) Number systems and their conversions in computers

(5) Programs and instructions 

(6) Level division of language

(7) Evolutionary history of mainstream languages

(8) IDE - Introduction to VisualStudio 2022

(9) C language is a process-oriented programming language

(10) Mind map

(11) Detailed knowledge summary 

2. Data types, operators and expressions of C language 

(1) Definition of variables

(2) Data type 

(3) Constants and symbolic constants

(4) Arithmetic expression 

(5) Priority of operators 

(6) Associativity of operators

(7) Auto-increment and auto-decrement operators 

(8) Mind map

(9) Detailed knowledge summary 




1. Overview of C language 

(1) Computer structure composition


(2) Computer system composition 


(3) ASCII code


(4) Number systems and their conversions in computers

In order to distinguish data in various counting systems, the following two methods are often used to express writing:

① Add the corresponding English letters after the numbers as identification, such as:    

  • B (Binary) represents binary number     
  • O (Octonary) represents octal number     
  • D (Decimal) represents a decimal number, usually its suffix can be omitted
  • H (Hexadecimal) represents a hexadecimal number

② Add numerical subscripts outside the brackets. This method is more intuitive, such as:

  • 11010011 in binary can be written as (11010011)₂.


(5) Programs and instructions 

An instruction is the smallest unit for program control of a computer .

The set of all instructions is called the computer's instruction system .

The computer is X86 and the mobile phone is ARM


(6) Level division of language


(7) Evolutionary history of mainstream languages


(8) IDE - Introduction to VisualStudio 2022

[C++] win 10 / win 11: Free download and installation of Visual Studio 2022 Community Edition https://gusanshang.blog.csdn.net/article/details/131277774


(9) C language is a process-oriented programming language


(10) Mind map


(11) Detailed knowledge summary 

[C Programming] Introduction to Learning: Introduction to C Language, Mind Map of C Knowledge Points https://gusanshang.blog.csdn.net/article/details/131941390
[Advanced Language Programming (1)] Chapter 1: Overview https ://gusanshang.blog.csdn.net/article/details/121674724

[Advanced Language Programming (1)] Chapter 2: Basic knowledge of C language https://gusanshang.blog.csdn.net/article/details/129847181

[C++ Programming] Chapter 1: Introduction to C++ language https://gusanshang.blog.csdn.net/article/details/130904977 [C++] win 10 / win 11: Visual Studio 2022 Community Edition free download and installation https:/ /gusanshang.blog.csdn.net/article/details/131277774



2. Data types, operators and expressions of C language 

(1) Definition of variables

① Various variables used in the program should be defined in advance, that is, defined first and then used .

② The definition of variables can include three aspects:

  • type of data
  • storage type
  • Scope

③ The so-called data types are divided according to the nature of the defined variables, the form of expression, the amount of storage space occupied, and the structural characteristics.

④ In C language, data types can be divided into:

  • Basic data types
  • Construct data type
  • pointer type
  • empty type 

(2) Data type 

type specifier

byte

Numeric range

Character type

char

1

character set

Basic integer type

int

4

-3276832767

Short

short int

2

-3276832767

long integer

long int

4

-214783648214783647

unsigned

unsigned

4

065535

unsigned long integer

unsigned long

4

04294967295

single precision real

float

4

3/4E-38 3/4E+38

Double precision real

double

8

1/7E-308 1/7E+308


(3) Constants and symbolic constants

A quantity whose value does not change during program execution is called a constant.

② Direct constant (literal constant):

  • Integer constants: 12, 0, -3
  • Real constants: 4.6, -1.23
  • Character constants: 'a', 'b'

③ Identifier: A valid character sequence used to identify variable names, symbolic constant names, function names, array names, type names, and file names. 


(4) Arithmetic expression 

① Arithmetic expression: An expression that uses arithmetic operators and parentheses to connect operands (also called operands) and conforms to C syntax rules.

② The following are examples of arithmetic expressions:

  • a+b
  • (a*2)/c
  • (x+r)*8-(a+b)/7
  • ++i
  • sin(x)+sin(y)
  • (++i)-(j++)+(k--) 

(5) Priority  of operators

Operator precedence:

  • In C language, the priority of operators is divided into 15 levels.
  • Level 1 is the highest and level 15 is the lowest.
  • Within expressions, those with higher precedence are evaluated before those with lower precedence.
  • When the operator priorities on both sides of an operand are the same, the associative direction specified by the operator's associativity is followed.

(6) Associativity of operators

Associativity of operators: There are two types of associativity of operators in C language, namely left associativity (from left to right) and right associativity (from right to left).

①Left associativity

  • For example, the associativity of arithmetic operators is from left to right, that is, left first and then right.
  • If there is an expression x-y+z, y should be combined with the "-" sign first to perform the xy operation, and then perform the +z operation.
  • This left-to-right combination direction is called "left associativity".

②Right  associativity

  • The direction of association from right to left is called "right associativity".
  • The most typical right associative operator is the assignment operator.
  • For example, x=y=z, due to the right associativity of "=", y=z should be executed first and then the x=(y=z) operation.
  • Many C language operators are right-associative, and you should pay attention to the differences to avoid misunderstandings. 

(7) Auto-increment and auto-decrement operators 

①Increase by 1 and decrement by 1 operator:

  • The auto-increment operator is marked as "++", and its function is to increment the value of a variable by 1.
  • The decrement operator is marked as "--", and its function is to decrement the variable value by 1.
  • The operators of incrementing by 1 and decrementing by 1 are both unary operations and have right associativity.

②It  can have the following forms:     

  • ++i   i increases by 1 before participating in other operations
  • --i    i decrements itself by 1 before participating in other operations
  • After i++   i participates in the operation, the value of i will increase by 1.
  • i--    After i participates in the operation, the value of i will be decremented by 1.

It is easy to make mistakes in understanding and using i++ and i--.

Especially when they appear in more complex expressions or statements, they are often difficult to figure out, so they should be analyzed carefully. 


(8) Mind map


(9) Detailed knowledge summary 

[Advanced Language Programming (1)] Chapter 3: Data Types, Operators and Expressions https://gusanshang.blog.csdn.net/article/details/129891802

Guess you like

Origin blog.csdn.net/qq_39720249/article/details/131994731