C ++ language overview

zhaozj2021-02-11  194

C language is an object-oriented programming language that uses it to implement object-oriented programming. Object-oriented design and process-oriented design is very different, object-oriented programming is a quality leap on the basis of the process-oriented programming. To learn the object-oriented programming, you must first learn to be an object-oriented language, that is, learn to use VC programming, you have to have C foundation, and learn the C language first to know the object-oriented characteristics and implement object-oriented object-oriented method.

C is an object-oriented programming language

When you study C for the first time, you will always encounter some concepts that have never seen before C language, such as: class, objects, abstractions, packages, inheritance, polymorphism, virtual functions, and more. These concepts are C , which brings together to introduce the support and implementation of C to the surface-to-face object programming method.

1, C support data package

Supporting data packages are supported data abstraction. In C , the class is a tool that supports data package, and the object is the implementation of the data package. The process-oriented programming method and object-oriented programming method is different in terms of data and function relationships, in the object-oriented programming, the data and the function of legal operation of the data are packaged together as a class. Definition, the data will be hidden in the package, the package exchange information by operating the interface. The object is illustrated with a given class variable, the class is similar to the structure in the C language, and the structure can be defined in the C language, but in this configuration, the data is included, and the function is not included. Categories in C are data and functions of the package. In C , the structure can be used as a special class, although it can contain functions, but it does not have a private or protected member.

2, C class included private, public and protected members

A member of three different access control permissions can be defined in the C class. One is a private member, only the function described in the class can access the private member of the class, and the function outside the class cannot access private members; the other is public (public) member, and the class is also Access to public members, becoming the interface of this class; there is also a protected member, which only the derived class of the class can be accessed, and the rest cannot be accessed outside of this class.

3, C by the pendant message to handle the object

In C , the object is handled by handling the object, each object determines the action you need to take according to the nature of the received message to respond to this message. In response to these messages are a series of methods, the method is defined in class definitions, using a mechanism similar to a function call to an object.

4, C allows you to destroy encapsulation

Private members in the class generally do not allow any functions outside of the class, but the friend can break this ban, which can access the private member of the class (including the data member and member function). Friends can be a function defined outside the class, or the entire class defined outside the class, the former is called the friend, and the latter is called a friend class. Friends broke the package of encapsulation, it is a C another object-oriented important animal.

5, C allows function name and operator overload

C supports polymorphism, C allows an identifier or operator representing a plurality of different implementations, this is called an identifier or operator overload, and the user can define an identifier overload or operator overload.

6, C supports inheritance

C can be allowed to inherit and inherit. A class can be generated as needed. Detective classes inherit all methods of the base class, and the parties you can define new methods that need not be included in the parent class. Each object of a subclass contains data members from the parent class and their own data members. 7, C supports dynamic networking

The virtual function can be defined in C to support dynamic linkage by defining the virtual function.

The above is the support of some of the main features in the design of C to objects.

C lexical and lexical rules

1, C character set

Characters are some minimum symbols that can distinguish. C characters set by case English letters (AZ and AZ), data characters (0-9), special characters (spaces,!, #,%, ^, &, *, _, <,>,, /, ,)composition.

2, words and lexical rules

Words also known as the lexical marker, which is a minimum lexical unit with a certain meaning of several characters. C has a total of 6 words, namely: identifier, keyword, operator, separator, constant, annotation, specifically paying special attention to the lexical rules of these words when encoding. It should be noted that the blank characters in C are often used in C . In fact, the blank character is not a character, which is a quote from the space character, a wrap, and a horizontal tab. Note that the blank character is not equal to the space character, but the blank character contains space characters. There is also an empty character, you have to separate it from the whistle. Empty characters refer to the character of the ASCII code value of 0. Empty characters have special purposes in C , with it as the end of the string. String constants stored in memory are finally ended, that is, empty characters, which is represented by the escape sequence method as '/ 0'.

Composition of C program structure

Basic components of the C program structure

1 Preprocessing command, C provides three types of preprocessing commands: macro definition command, file contains commands, and conditional compile commands.

2 Input and output, the C program always does not minimize the input and output of the input and output communication with the inside of the program. Especially the features of the screen output, almost every program is used, using it to display the results of the computer on the screen.

3 Functions, C programs consist of several files, each file is composed of several functions, so a program that can be considered C is a function string, which is composed of several functions, and the function is relative. And it is parallel, and the function can be called. There must be one main () in a number of words that make up a program.

4 statement, statement is the basic unit of the constituent program. The function consists of several statements. However, the empty function is no statement. The statement is made up of words, and the words between the words are separated by spaces, and the statements in the C program are at the end of the semicolon. In addition to expression statements and empty statements, there are several classes such as composite statements, branch statements, cyclic statements, and steering statements.

5 variables, most programs need to be explained and used. Generalized, the object contains variables, that is, the variable is also called an object, a narrow, regarding objects as an instance of a class, an object refers to an object of a class.

6 Others, in addition to the five parts described above, there are other components. For example, symbol constants and annotation information are also part of the program. C is tried to define the constant as a symbol constant, and the symbol constant appears in the C program, which represents a certain confirmation value. C program writing format

At the time of programming, you should pay attention to the writing format of C . The basic principle is: a line generally write a statement. The phrase can write multiple words. The long statement can be written multiple lines. The principle of branch cannot separate a word. A string referenced by dual quotation marks is also best not separated. If you must separate, some compile systems require the row ("/")

C program realization

The implementation of the C source program is the same as the principle of other advanced language source program. Generally, editing, compiling, and running. The most important thing is the compilation process, and C is a high-level language implemented in compilation. The implementation of the C program must be compiled using a C language compiler. The function of the compiler is to convert the source code of the program into machine code, called the target code; then, the target code is connected to generate an executable. This process can be divided into three sub-processes: pre-processing, compilation process (lexical analysis, grammatical analysis, symbolic table, error handler, generating target code), connection process.

Visual C 6.0 is a C compilation system that is currently more popular in China.

This article only provides a simple introduction to some of the contents of the C language. Relevant concepts and characteristics will be introduced in this column, please pay attention! At the same time, you will also welcome your manuscript to participate and communicate.

转载请注明原文地址:https://www.9cbs.com/read-3814.html

New Post(0)