Relations and differences between C and C ++ | CC ++ language 0

1 C language

The reason why the C language designated C, B is derived from the C language because language Ken Thompson invention, and B is derived from the language BCPL language.

In 1967, Martin Richards of the University of Cambridge CPL language has been simplified, so have the BCPL (Basic Combined Programming Language) language. And he wrote the first B language UNIX operating system.

In 1972, Bell Labs DMRitchie B on the basis of language on the final design of a new language, he took the second letter as the name of the language BCPL, which is the C language.
Finally, if you if you encounter difficulties in learning, looking for a C ++ learning environment, can join our Learning Circle C ++, click I joined it , it will save a lot of time, reduce the number of problems encountered in the study.
Relations and differences between C and C ++ | CC ++ language 0

C language is very simple, only 32 keywords, nine kinds of control statements, 34 kinds of operators.

Specifically, C language is a structured language, with emphasis on implementing data structures and algorithms. Design of primary consideration is how the C program, the input (or ambient conditions) calculation processing performed by a process to obtain an output (or implementation (object) control).

C language can do anything useful, but it is most useful to write operating systems and compilers like.

C language is very efficient, very often you need to consider what the underlying memory management. Unfortunately these require you to spend a lot of time to do it. As an underlying programming language, it may be performed by a direct memory pointer management addition, many of the C language is designed, such as perl, java, python.

C language is a universal programming language with high-level language features, but also has assembly language features. , 1978, C language it has already been ported to the big, the medium and small and microcomputer, it can be used as a working system design language, writing system, applications, or as application programming language to write applications do not rely on computer hardware . Its wide range of applications, with strong data processing capabilities, not just in software development, but also various types of research need to use C language, suitable for writing system software, three-dimensional, two-dimensional graphics and animation, such as the specific application microcontrollers and embedded systems development. Although the C language for the realization of operating system software and design, but it is also widely used in the development of portable applications.

1.1 C language is a structured programming, having a variable scope (variable scope) and recursive functions procedural language.

1.2 C language parameter has a value passed passed (pass by value) and passing a pointer (a pointer passed by value) in two ways.

1.3 Different types of variables may be combined with the structure (struct) together.

1.4 only 32 reserved word (reserved keywords), the variable, the function names have more flexibility.

1.5 part of the variable type can be converted, for example, integer and character variables.

1.6, C language can be easily controlled by the lower of the memory pointer (pointer).

Compiler 1.7 pre-compiled process (preprocessor) allow the C language more flexible.

Sample code:

#include <stdio.h>
int main(void)
{
printf("hello, world!n");
return 0;
}
2 C++语言

The mid-1970s, Bjarne Stroustrup work at Cambridge University Computer Center. He used Simula and ALGOL, contact C. His deep feelings on Simula's class system, the structure of ALGOL research is also very well aware of the significance of operating efficiency. Both programming is simple, accurate and reliable, but also to run efficient, portable, Bjarne Stroustrup is the original intention. With C as the background to Simula based on the idea, exactly in line with his vision. In 1979, Bjame Sgoustrup to Bell Labs, began working for the improvement of the C with Classes C (C with classes) work. In 1983 the language was officially named C ++.

Thus, C ++ is a continuation and development of C. C ++ powerful, can develop in response to large-scale applications. That object can be oriented and to be compatible in C, procedures may face.

C ++ is a complex, difficult to grasp the language, not only in its grammar, but also in thinking that provides the programming model on top of four kinds, including: procedural-based, object-based, object-oriented, generic paradigm. C ++ is a result of both the efficiency and elasticity; both objects can be oriented, process-oriented and compatible.

Process-oriented thinking: analysis steps needed to solve the problem, use these steps in order to achieve the function.

Object-oriented thinking: the affairs of a problem is decomposed into individual objects, the purpose of creating an object, not a complete one step, but rather describe the behavior of a transaction in solving the whole problem steps.

As it can be seen from the above description, in fact, object-oriented and process-oriented Reflections are two ways to solve the problem, differing mainly in that the angle of reflection.

C ++ programmers circle the word in mainland China is commonly read as "C Gaga", and the West programmers usually read as "C plus plus", "CPP". It is a very widely used computer programming language. C ++ is a static data type checking, support for multiple programming paradigms of universal programming language. It supports procedural programming, data abstraction, object-oriented programming, generic programming and other programming style.

C ++ is one of the most popular programming language, its use applications include a system software, application software, drivers, embedded software, high-performance server and client applications such as video games and other entertainment software.

2.1 Simple (Simple)

C ++ is a simple language that provides a structured approach (to break the problem into smaller parts), rich data types, class libraries and the library function sets and the like.

2.2 independent machine or graft (Portable)

And different assembly language, C / C ++ language program can be executed in many machines, but there may be little or no change. But it is not platform-independent.

2.3 Intermediate programming language (Mid-level)

C ++ is also used to make low-level programming. It is used in developing system applications, such as the kernel, drivers, and the like. It also supports high-level language features. This is why it is called intermediate language.

2.4 structured programming language (Structured)

C ++ is a structured programming language, we can use the function program into a plurality of small portions. So, it is easy to understand and modify.

2.5 rich library (Rich Library)

C ++ provides a number of built-in functions (libraries), some of the commonly used functions did not have to start over writing help improve development speed.

2.6 memory management (Memory Management)

It supports dynamic memory allocation characteristics. In the C ++ language, you can always release the memory allocated by calling the free () function.

2.7 runs fast (Fast Speed)

C ++ language compile and execution time are very fast.

2.8 function pointer (Pointers)

C ++ provides a function pointer. It may interact directly with the memory by using a pointer. We can use memory pointers, structures, functions, arrays, and so on.

2.9 Recursion (Recursion)

In C ++, function within the function can be called. It provides code reusability for each function.

2.10 Extensible (Extensible)

C ++ language is extensible, because it can more easily adopt the new features.

2.11 Object Oriented (ObjectOriented)

C ++ is object-oriented programming (OOP) language. OOP the development and maintenance become easier, because in the process-oriented programming language, if the code size of the project grows and growth, is not easy to manage.

2.12 based compiler (Compiler based)

Simply speaking, the compiler is the "one language (usually high-level language)" "another language (usually low-level language)" program for the translation. The main work processes a modern compiler: the source code (source code) → pre-processor (preprocessor) → compiler (compiler) → object code (object code) → Linker (Linker) → executable programs (executables).

Sample code:

#include <the iostream>
int main ()
{
STD :: COUT << "the Hello, n-World!";
}
associated with the difference between 3 C and C ++

C is a process-oriented programming language, its most important feature is the function to call each subroutine by the main function. Running order is decided beforehand good programmer.

C ++ is an object-oriented programming, its main features class produced during program execution, first into the main function of the main, defined classes, based on the concept of class member functions need to be performed, the process being diluted (in fact, the process is still Yes, that is the main function of which statements) to run the class driver, class is the object, so we called object-oriented programming. Operation of object-oriented analysis package and the time to solve the problem, and the data related to the data in the class, the class can be created by an object, or a message to an event driven processing on the object.

The biggest difference between C and C ++ is that they solve the problem of thinking is not the same. C language mainly used in the field of embedded, hardware-driven development and other areas and deal directly, C ++ can be used to develop application layer, user interface development is equal to operating systems deal.

4 C ++ to C "enhanced"

4.1 type checking more stringent.

4.2 adds object-oriented mechanism.

4.3 increases the mechanism of generic programming (Template).

4.4 adds exception handling.

4.5 increasing the Operator.

4.6 adds the Standard Template Library (STL).

An increase of 4.7 namespace, global namespace to avoid conflict.

C ++ inherits the strong underlying operating characteristic C, it has been given an object-oriented mechanism textbook. It is characteristic of many, there are more than rare inherited other object-oriented languages, there are intriguing to pass the value passed by reference and const keyword, and so on. C ++ is like a Swiss ×××, or like a toolbox, which provides as many tools as you, so much that people are not familiar with it know what to do, so that people know how to use it like a duck. All the C ++ features that make it well suited for the preparation of the underlying data structures, algorithms, libraries, system software development and mathematical models to build such a powerful arsenal, known as industrial-level programming language.

Most of the code C can be used in C ++, and C ++ code can not be applied C. (Remember that most, not all).

It is not compatible with the 5 C ++ and C at

It says most of the code in C, C ++ can run on a yo, but there are a few C code will fail in C ++, or behave differently in C ++. For example: implicit conversion.

One of the most common difference is 5.1, C allows implicit conversion from void * to other pointer types, but C ++ is not allowed. The following C code is valid:

//从void*类型隐式转换为int*类型
int *i=malloc(sizeof(int)*5);

But to make it operational have encountered in both C and C ++, you need to use explicit conversions:

int *i=(int*)malloc(sizeof(int)*5);

5.2 In C, a global variable declared more than once, although not desirable, but not wrong. In C ++, repeatedly declared the same global variable can cause errors.

5.3 Another common problem is portable, C ++ defines a new keyword, such as new, class, they can be used as in the C program identification word (Example: variable name).

In the C Standard (C99) removes some of the incompatibilities, C ++ also supports a number of features, such as // comments, as well as mixed statements in the code. C99 but also incorporate the new features and several C ++ conflict (eg: variable length array, a plurality of primary and Composite literally constant).

5.4 To mix C and C ++ code, all C code in C ++ calls must be placed extern "C" {/ C code /} within.Relations and differences between C and C ++ | CC ++ language 0

CC ++ language 0 | connections and differences C and C ++
6 suggestions from C to C ++

6.1 Macro caution

6.1.1 replace #define macro substitution with const

#define PAI 3.14 //慎用
const double PAI = 3.14 // 推荐

6.1.2 Enumeration make more relevant elements

ERROR 0 #define
#define SUCCESS. 1
// recommended the following wording
enum {ERROR the STATE, SUCCESS}
6.1.3 use inline function instead of macro parameters

max #define (A, b) ((A)> (b)? (A) :( b))
// recommends the following wording

int max inline (A int, int B) {
return A> B A:? B;
}
6.2 variable initialization statement also used with

6.3 to make use of new / delete substituted malloc / free

6.4 less void *, pointer arithmetic, unions, and casts

6.5 less c-style char *, string representing a multi-string

-End-

Guess you like

Origin blog.51cto.com/14209412/2401944