The difference between C language and C++ and C#

Today I am suddenly curious about the three languages ​​C, C++ and C# have a C, so what is the relationship between them? So I went to Google and found this article: Understanding the Differences Between C#, C++, and C-C# Station . After reading it, I felt that I wrote it well, so I decided to translate it.

It should be noted that my skills are very limited, so the accuracy of translation may be questionable. It is recommended that students who have a basic English knowledge can directly read the source site.

Start

If you are an aspiring programmer, it may be difficult for you to decide which programming language to learn first. There are quite a few programming languages ​​in the world, but which of C, C++ and C# is the most useful?

Learning C++ well is the stepping stone to entering a major factory! If I had this class back then, my C++ wouldn’t be like this

You may have heard of these three variations of the C language. Before you make a choice, you need to understand the difference.

C

We start with the C language, because it is the oldest and most widely used language of the three. Dennis Ritchie created the C language in 1972 and published it in 1978. Ritchie's original intention of designing C was to develop a new version of Unix.

Until then, Unix using assembly language (assembly language), it is the most computer-readable low-level programming. The birth of the C language revolutionized programming and operating systems. The rest, as they say, is a piece of history. (Translator's Note: Just to praise the C language is very awkward.)

Translator's Note: The low-level or high-level of the language does not mean how powerful the language is. Low-level refers to being closer to the bottom level. The computer executes faster but is not conducive to human understanding, while the high-level is the opposite.

C is also a low-level programming language, its efficiency is close to assembly. It provides a base-level way of accessing memory and requires very little runtime support.

Although it has been born for more than 40 years, it is still widely used. Developers still use it for operating systems, kernel-level software development, hardware drivers, and applications that need to work with old code.

Many established schools will recommend C as the language of choice, because many later languages ​​have borrowed from C. Due to C's age, the use of C may also bring some safety improvements. Because there are fewer users using C, it is less likely to be a target of hackers.

C++

C++ was developed as an extension of C. It was developed by Bjarne Stroustrup, a Danish doctor of philosophy (Ph.D.). His goal is to enhance the C language and increase its object-oriented capabilities without sacrificing speed and efficiency.

C++ is considered an intermediate language because it is based on the low-level C language and has some high-level capabilities.

Since its release in 1985, it has become another highly productive programming language. It will cooperate with C when developing the operating system, but it can also be seen on some high-profile servers and PC software.

Translator's Note: high-profile can be understood as a high-profile meaning, such as the Razer and Alien series in the game PC field.

If you have a solid foundation in C language, then it is easy for you to understand C++; however, if you want to experience object-oriented programming immediately, you can also use C++ as your first programming language. (Translator's Note: Shouldn't it be the first time to find a target?)

C#

C# is a high-level object-oriented programming language, which is also created as an extension of C. It was developed in 2002 by Anders Hejlsberg, the leader of a Microsoft team. It is based on the .NET framework, but its core is still the C language.

C# compiles the code into byte-code instead of machine code (0101 binary). This means that it will run on a virtual computer that translates bytecode into machine code in real time (on the fly). It adds garbage collection, uninitialized variable checking, bound checking, and type checking to the C language.

Translator's Note: When I translated here, I thought of Java and JVM.

C# is commonly used in internal or enterprise applications rather than commercial software. It can be found in client-side and server-side development in the .NET framework.

Although C# is the most technically complex of the three languages, its grammar is less error-prone than C and C++, so it is relatively faster to learn.

The main difference

Although C and C++ have many differences, they are essentially very similar programming languages. In C#, in other words it will be more similar to Java.

C vs. C++

To fully understand the difference between C and C++, you need to understand what object-oriented is. The term object-oriented in programming languages ​​originated in the late 1950s or early 1960s and was proposed by the Massachusetts Institute of Technology (MIT).

Object-oriented programming (OOP) uses a concept called object. An object is an instance of a class or a program code template. Classes can be composed of data and code procedures (procedures, also called methods).

C language does not support object-oriented, which is the biggest difference between it and C++. C is a pure procedural programming language, and C++ is a hybrid programming language that supports both procedural and object-oriented .

The following are other differences between C and C++:

  • C++, as an extension of C, means that it can run most of the C code. But on the other hand, if C runs C++ code, it won't work.
  • As an object-oriented language, C++ supports polymorphism, encapsulation, and inheritance, but C does not.
  • In C, data and functions are "free entities", which means you can use external code to manipulate them. But because C++ encapsulates data and functions into a single object, it is equivalent to hiding the external code, so the external code cannot manipulate its data and functions.
  • C++ uses namespaces to organize code into logical groups and prevents name collisions. Name conflicts can occur when your code base contains multiple libraries. C does not use namespaces.
  • C uses functions to implement input and output, while C++ uses objects to implement input and output.
  • C++ supports reference variables, but C does not. Reference variables are aliases of existing variables and can be used to speed up coding.
  • C does not support error and exception handling, but C++ does.

C++ vs. C#

As a more modern programming language, C# is designed to work with the current Microsoft .NET framework and is used in both client and web applications.

C++ is an object-oriented language, and C# is considered a component-oriented programming language. Object-oriented programming focuses on combining multiple classes and linking them into an executable binary program, while component-oriented programming uses interchangeable code modules (that can run independently) and you don’t need to know how they work internally to use them .

The following are the main differences between C++ and C#.

  • C++ compiles the code into machine code, and C# compiles the code into CLR (a virtual machine component of the .NET framework, which will be parsed by ASP.NET).
  • C++ requires users to handle memory manually, but C# runs in a virtual machine, and the virtual machine automatically handles memory.
  • C# does not use pointers, while C++ can use pointers at any time. [C# does not support pointers by default for type safety (the same as Java), but it also has pointers, but it is best not to use them, because pointers are not safe, the delegate in C# is already equal to the pointer in C++]
  • Although C++ is designed for Unix or Unix-like systems, it can run on any platform. Although C# has been standardized, it basically only runs under the Windows environment.
  • C++ can create stand-alone and console programs. C# can create console, Windows, http://ASP.NET and mobile (mobile) programs, but not independent programs.

C vs. C#

Although C and C# are technically related to each other, they are almost completely different languages, so there are more differences between them. Students with C language skills will learn C# easier, because some of the syntax is similar; however, even if you don’t have a C language foundation, you can easily learn C# because its syntax is very simple (Translator’s Note: the original text is forgiving, tolerant).

 

How to choose your first programming language?

Now that you have a clear understanding of the difference between these three languages, how do you choose?

Rookie programmer

If you have never been exposed to programming before, many computer science experts will suggest that you prefer the C language. Not only because it has fewer options than its successors (Translator's Note: This should refer to language features, such as decorators, garbage collection, etc.), but also the grammar and concepts of many languages ​​are borrowed from C . In short, after you learn C, you can learn any other language easily.

Intermediate programmer

If you have previous programming experience, then you can try C++. Nowadays, object-oriented programming is more common than procedural programming. If you already have some OOP experience, then you will learn C++ faster.

Advanced programmer

If you already have development experience in multiple programming languages, then your choice depends on what you hope to get in your new programming experience.

Some young developers choose to learn the C language to learn the basics of coding. Experienced seniors often look down on the younger generation because they don’t respect their roots. Your knowledge can be used as street cred in a new job. (Translator's Note: Street credibility can be understood as being respected by some people in a certain field, for example, Jordan is to basketball, but the street may be more like what happens around)

C++ has a wide range of applications in the work environment, so having C++ development capabilities can bring many job opportunities. If you already have OOP experience and want to try a new OOP language with minimal learning costs, then C++ is a good choice.

If you want to work in the Microsoft .NET website development environment, then C# is the best choice. Although its use is not as extensive as the first two, it still has a place.

 

[Note: This is a personal study reading note. For the original text, please see-Code Ball's Answer-Knowing: https://www.zhihu.com/question/21610243/answer/1470744912]

Guess you like

Origin blog.csdn.net/Dust_Evc/article/details/113666105