Introduce some programming languages - C language

Introduce some programming languages ​​- C language

C language

Introduction

C language is a process-oriented computer programming language, which is different from object-oriented programming languages ​​such as C++, C#, and Java. The design goal of the C language is to provide a programming language that can be compiled in an easy way, handle low-level memory, generate only a small amount of machine code, and can run without any operating environment support.

C language describes problems faster than assembly language, with less workload, better readability, easy debugging, modification and transplantation, and the code quality is equivalent to assembly language. C language is generally only 10% less efficient than the target program generated by assembly language code 10\%10% to20 % 20\%20% . Therefore, C language can write system software.

At the current stage, in the field of programming, C language is widely used. It takes into account the advantages of high-level language and assembly language, and has greater advantages than other programming languages. Computer system design and application programming are two major fields of application of C language. At the same time, the C language has strong universality and can be applied in many computer operating systems with remarkable efficiency.

C language has a complete theoretical system with a long history of development, and plays a pivotal role in programming languages.

Development History

The C language was born in Bell Laboratories in the United States. It was developed by Dennis MacAlistair Ritchie based on the B language designed by Kenneth Lane Thompson. After its main design was completed, Thompson and Rich used it to completely rewrite UNIX, and with the development of UNIX, the C language has also been continuously improved. In order to facilitate the comprehensive promotion of C language, many experts, scholars and hardware manufacturers jointly formed the C language standard committee, and in 1989 and 1989In 1989 , the first complete C standard was born, referred to as C89, which is "ANSI C", as of2020 2020In 2020 , the latest C language standard is2018 2018June 6, 2018C18 released in June .

1967 1967 In 1967 , Martin Richards of Cambridge University simplified the CPL language, resulting in the BCPL (Basic Combined Programming Language) language. That is the B language.

20 20 20th century60 60In the 1960s , Kenneth Lane Thompson (Kenneth Lane Thompson), a researcher at AT&T Bell Laboratories in the United States, had nothing to do, his hands were itchy, and he wanted to play a video game that he made up himself to simulate sailing in the solar system—— Space Travel. Behind his boss's back, he found an idle small computer - PDP-7. But the computer didn't have an operating system, and games had to use some features of the operating system, so he set out to develop an operating system for the PDP-7. Later, this operating system was named - UNICS (Uniplexed Information and Computing Service).

1969 1969 In 1969 , Ken Thompson of Bell Laboratories in the United States, based on the BCPL language, designed a very simple and hardware-friendly B language, and wrote the first version of the UNIX operating system called UNICS in B language.

1971 1971 In 1971 , Dennis Rich, who also loves Space Travel, joined Thompson's development project in order to play the game earlier, and jointly developed UNIX. His main job is to transform the B language and make it more mature.

1972 1972 In 1972 , Dennis Rich of Bell Laboratories in the United States finally designed a new language based on the B language. He took thesecond letteras the name of this language, which is the C language.

1973 1973 In early 1973 , the main body of the C language was completed. Thompson and Rich couldn't wait to start completely rewriting UNIX with it. At this time, the fun of programming made them completely forget about the Space Travel, and devoted themselves to the development of UNIX and C language. With the development of UNIX, the C language itself is constantly improving.

Until 2020 2020In 2020 , various versions of the UNIX kernel and peripheral tools still use the C language as the main development language, and many of them inherit the codes of Thompson and Rich.

During development, they also considered porting UNIX to other types of computers. The powerful portability of the C language appears here. Neither machine language nor assembly language is portable, and programs developed for x86 cannot run on machines such as Alpha, SPARC, and ARM. The C language program can be used on processors of any architecture, as long as the processor of that architecture has the corresponding C language compiler and library, and then the C source code is compiled and linked into the target binary file . architecture the processor runs on.

1977 1977 In 1977 , Dennis Ritchie published a C language compilation text "Portable C Language Compiler" that does not depend on a specific machine system.

The C language continued to develop in 1982 1982In 1982 , many people of insight and the American National Standards Institute decided to set up the C Standards Committeeto establish the C language standardin order to make the C language develop healthilyThe committee is composed of hardware vendors, compiler and other software tool manufacturers, software designers, consultants, academics, C language authors, and application programmers.

1989 1989 In 1989 , ANSI released the first complete C language standard - ANSI X3.159-1989, referred to as C89, but people are also used to call it "ANSI C". C89 in1990 1990It was adopted by the International Organization for Standardization—ISO in 1990 without change. The official name given by ISO is: ISO/IEC 9899, ​​so ISO/IEC9899:1990 is also usually referred to as "C90". In 1999, after making some necessary amendments and improvements, ISO released a new C language standard, named ISO/IEC 9899:1999, referred to as C99.

in 2011 2011December 12, 2011December 88On the 8th , ISO officially released a new standard called ISO/IEC9899:2011, referred to asC11.

Language Features

main feature

C language is a structured language, it has a clear hierarchy , and the program can be written in the form of modules, which is very conducive to program debugging, and the processing and performance capabilities of C language are very powerful, relying on very comprehensive calculations Symbols and various data types can easily complete the construction of various data structures. Through the pointer type, the memory can be directly addressed and the hardware can be directly operated. Therefore, it can be used to develop system programs and application software. Through the research and analysis of C language, its main features are summarized as follows:

  1. concise language

The various control statements contained in the C language are only 9 9There are 9 types, and there are only32. The writing requirements of the program are not strict and are mainly in lowercase letters, and many unnecessary parts have been streamlined. In fact, the structure of statements is rarely related to hardware, and C language itself does not provide hardware-related input and output, file management and other functions, so C language has a very simple compilation system.

  1. with structured control statements

C language is a structured language, and the control statements provided have structural features , which can be used to realize the logic control of functions and facilitate process-oriented programming.

  1. rich data types

The C language contains a wide range of data types, including not only traditional character types, integer types, floating point types, array types and other data types, but also data types that other programming languages ​​do not have. Among them, pointer type data is the most flexible . Computations can be performed programmatically on various data structures.

  1. rich operator

C language contains 34 34There are 34 operators. It treats assignment, parentheses, etc. as operators to operate, so that the expression types and operator types of C programs are very rich.

  1. Direct manipulation of physical addresses is possible

The C language allows direct reading and writing of hardware memory addresses, so that the main functions of assembly language can be realized and the hardware can be directly operated . C language not only has the good features of high-level languages, but also contains the advantages of many low-level languages, so it is widely used in the field of system software programming.

  1. Code is more portable

C language is a process-oriented programming language. When using C language to achieve the same function, the code is basically the same, and the transplantation can be completed without or only a small amount of modification, thus greatly reducing the work intensity of program transplantation.

  1. Generate high-quality programs with high object code execution efficiency

Compared with other high-level languages, C language can generate high-quality and high-efficiency object code, so it is usually used in the writing of embedded system programs that require high code quality and execution efficiency.

unique features

C language is the most universal computer program editing language. It can not only play the role of high-level programming language, but also has the advantages of assembly language. Therefore, compared with other programming languages, it has its own unique characteristics. Specifically, it is reflected in the following three aspects:

  • One, extensiveness. The size of the operating range of the C language directly determines its pros and cons. The C language contains 34 34There are 34 operators, so the scope of operation is beyond that of many other languages, and the expression forms of its operation results are also very rich. In addition, the C language includes a variety of data structure forms such as character type and pointer type, so it can also handle larger data structure operations.

  • Second, simplicity. 9 99 types of control statements and32 32The 32 keywords are the basic features of C language, which makes it widely applicable in computer application programming. It can not only be suitable for the operation of programmers, improve their work efficiency, but also support advanced programming, avoiding the Language switching is cumbersome.

  • Third, the structure is perfect. C language is a structured language, which can realize modular application programs by building module units, and has significant advantages in system description. At the same time, this feature also makes it adaptable to many different programming requirements, and High execution efficiency.

shortcoming

  1. The disadvantage of C language is mainly manifested in the weak encapsulation of data, which makes C language have great defects in data security, which is also a big difference between C and C++.

  2. The syntax restrictions of the C language are not too strict , and the type constraints on variables are not strict , which affects the security of the program, and there is no check for array subscripts out of bounds, etc. From the perspective of application, C language is more difficult to master than other high-level languages. In other words, for those who use C language, they are required to be more proficient in programming.

Programming DevelopmentEdit

translater

GCC, an open source and free compiler developed by the GNU organization

MinGW, GCC under Windows OS

Clang, an open-source BSD-licensed LLVM-based compiler

Visual C++ :: cl.exe, the compiler that comes with Microsoft VC++

Integrated Development Environment

Code::Blocks, an open source and free C/C++ IDE

CodeLite, an open source, cross-platform C/C++ integrated development environment

Dev-C++, a portable C/C++ IDE

C-Free

Light Table

Visual Studio series

simple program

Print Hello World!

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

Calculate A + B problem

#include <stdio.h>
int main(){
    
    
	int a, b;
	scanf("%d%d", &a, &b); 
    printf("%d", a + b);
    return 0;
}

Judging parity

#include <stdio.h>
int main(){
    
    
	int a;
	scanf("%d", &a);
	if(a % 2 == 0) {
    
    
		printf("是偶数");
	}
	else {
    
    
		printf("是奇数");
	}
    return 0;
}

Calculate 1 + 2 + 3 + ⋯ + ( n − 1 ) + n 1+2+3+\dots+(n−1)+n1+2+3++(n1)+the value of n

#include <stdio.h>
int main(){
    
    
	int n, sum;
	scanf("%d", &n);
	int i;
	for(i = 1; i <= n; i ++) {
    
    
		sum += i;
	}
	printf("%d", sum);
    return 0;
}

Guess you like

Origin blog.csdn.net/ZH_qaq/article/details/131057597