Quick Start with C Language

1.What is C language

*** C language** is a general computer programming language that is widely used in low-level development. The design goal of the C language is to provide a programming language that can be easily
compiled, handle low-level memory, generate a small amount of machine code, and can run without any runtime environment support
.
Although the C language provides many low-level processing functions, it still maintains good cross-platform characteristics. A
C language program written in a standard specification can be compiled on many computer platforms, even including some embedded processors (microcontrollers or (called MCU) and supercomputers
and other operating platforms.
In the 1980s, in order to avoid differences in the syntax of the C language used by various developers, the American National Bureau of Standards
formulated called ANSI C, as the original standard for the C language. standard. [1] Currently on December 8, 2011
, the C11 standard released by the International Organization for Standardization (ISO) and the International Electrotechnical Commission (IEC) is the third official
standard latest standard for the C language. This standard is better It supports Chinese character function names and Chinese character identifiers, realizing Chinese
character programming to a certain extent.
C language is a process-oriented computer programming language, which is different from object-oriented programming languages ​​such as C++ and Java.

Its compilers mainly include Clang , GCC , WIN-TC , SUBLIME , MSVC , Turbo C , etc.

2. The first C language program

#include <stdio.h>
int main()
{
    
    
	printf("Hello World\n");
	return 0;
}

3.Data type

char //Character data type
short //Short
int //Integer
long //Long integer
long long //Longer integer
float //Single precision floating point number
double //Double precision floating point number

Note: There are so many Type is actually to express various values ​​in life more abundantly.
Insert image description here

4. Constants and variables

4.1 Naming of quantities

1. Can only consist of letters (including uppercase and lowercase), numbers and underscores (_).
2. Cannot start with a number.
3. The length cannot exceed 63 characters.
4. Variable names are case-sensitive.
5. Keywords cannot be used in variable names.

4.2 Classification of variables

1. Local variables
2. Global variables

Insert image description here
Note: When global variables and local variables have the same name, the local variables take precedence.

4.3 Scope and life cycle of variables

Scope

  1. The scope of a local variable is the local scope where the variable is located.
  2. The scope of global variables is the entire project.

Life cycle (the life cycle of a variable refers to the time period between the creation of the variable and the destruction of the variable)

  1. The life cycle of local variables is: the life cycle begins when entering the scope and ends when leaving the scope.
  2. The life cycle of global variables is: the life cycle of the entire program.

4.3 Constants

The definition forms of constants and variables in C language are different.
Constants in C language are divided into the following types:
literal constant
const modified constant variable
#define defined identifier constant
enum constants

#include <stdio.h>
//举例
enum Sex
{
    
    
	MALE,
	FEMALE,
	SECRET
};
//括号中的MALE,FEMALE,SECRET是枚举常量
int main()
{
    
    
	//字面常量演示
	3.14;//字面常量
	1000;//字面常量
	//const 修饰的常变量
	const float pai = 3.14f; //这里的pai是const修饰的常变量
	pai = 5.14;//是不能直接修改的!
	//#define的标识符常量 演示
#define MAX 100
	printf("max = %d\n", MAX);
	//枚举常量演示
	printf("%d\n", MALE);
	printf("%d\n", FEMALE);
	printf("%d\n", SECRET);
	//注:枚举常量的默认是从0开始,依次向下递增1的
	return 0;
}

Note: pai in the above example is called a const-modified constant variable. The const-modified constant variable is only restricted at the grammatical level in C language.
The variable pai cannot be changed directly, but pai is essentially a variable, so it is called a constant variable.

5.Operator

arithmetic operators

  +  -   *   /   %

displacement operator

  >>  <<

Bit operators

  |   &   !

assignment operator

  =  +=   -=  *=  /=   &=   ^=   |=  <<=   >>=

Unary operator

  ! Logical inversion operation
  - negative value
  + positive value
  & take the address
  sizeof type length of the operand (in bytes)
  ~ binary bitwise inversion of a number
  - prefix, postfix -
  ++ prefix, postfix ++
  * Indirect access operator (dereference operator)
  (type) forced type conversion

Relational operators

=
<
<=
!= is used to test "inequality"
== is used to test "equality"

Logical operators

&& logical AND
|| logical OR

conditional operator

exp1 ? exp2 : exp3

comma expression

exp1, exp2, exp3, …expN

Subscript references, function calls, and structure members

[]   ()   .   ->

6.Keywords

C language provides a wealth of keywords, which are preset by the language itself. Users cannot create keywords themselves.

auto  break  case  char  const  continue  default  do double  else  enum
extern  float  for  goto  if  int  long  register  return  short  signed
sizeof  static  struct  switch  typedef  union  unsigned void  volatile  while

6.1 Keyword typedef

As the name suggests, typedef is a type definition, which should be understood as type renaming.
for example:

//将unsigned int 重命名为uint_32, 所以uint_32也是一个类型名
typedef unsigned int uint_32;
int main()
{
    
    
//观察num1和num2,这两个变量的类型是一样的
unsigned int num1 = 0;
uint_32 num2 = 0;
return 0;
}

Guess you like

Origin blog.csdn.net/qq_58032742/article/details/131865777