How to learn C language well?

⭐Column introduction

This column will continue to update various questions about JAVA, including interview questions, JAVA introduction to proficiency, etc.

The update speed remains at 3-5 articles per day
Insert image description here
. C language is process-oriented, while C++ is object-oriented.

The difference between C and C++:

C is a structured language whose focus is on algorithms and data structures. The primary consideration in the design of C programs is how to perform operations on input (or environmental conditions) to obtain output (or implement process (transaction) control) through a process.

In C++, the first consideration is how to construct an object model so that this model can fit the corresponding problem domain, so that output or process (transaction) control can be achieved by obtaining the status information of the object. So the biggest difference between C and C++ lies in their different ways of thinking about solving problems. The reason why C++ is more advanced than C is because "the concept of design has been integrated into C++."

The biggest difference between C and C++ lies in their different ways of thinking about solving problems. The reason why C++ is said to be more advanced than C is because "the concept of design has been integrated into C++", and as far as the language itself is concerned, C has more of an algorithmic concept. Then it doesn’t matter whether it is C or not, wrong! Algorithms are the basis of programming. Good design will not work without good algorithms. Moreover, "C plus good design" can also write very good things.

When it comes to C language, I think everyone should know that C language is powerful and widely used. Once you master it, you can confidently say to others "I am a computer expert!", and it will be easy to learn other languages ​​​​by yourself in the future. . The worry is that the C language is as broad and profound as it is too difficult to learn. In fact, the author believes that C language is not "difficult", as long as you can clarify your thinking, master its essence, and use a set of teaching materials. So learning C language is very easy and endless fun. Today I will talk with you about how to learn C language or what aspects should be started in learning C language.

1. Background of C language

From my personal experience, no matter which language you learn, you should first understand the background of the language you are learning, or its development history.

C language is a kind of high-level programming language, and its predecessor is "ALGOL". Its founders were Brown W. Carnihan and Dennis M. Leach. When the C language came out, it had great limitations because it could only be used on UNIX systems. However, with the advancement of science and technology and the development of the computer industry, C language gradually separated from UNIX. In 1987, the American Standards Institute formulated the international standard for C language, referred to as "ANSI C". Since then, it has become a widely used programming language. C language has many advantages, the main ones are as follows:

1. It has the advantages of both high-level and low-level languages ​​and is an intermediate language.

2. It is a structured programming language and is very suitable for structured programming.

3. There are rich data types, operators and functions to choose from.

4. Deal with memory directly, making it easy and simple to modify and edit other programs and documents.

2. Two different learning methods for the two major language families

I have learned many programming languages, such as: C, C++ (extension of C language), QBASIC, VB (visualization of BASIC), javascript, JSCRIPT, VBSCRIPT, JAVA, ASP, FOXPRO, PERL, etc. From what I have learned through practice, in fact, advanced Programming languages ​​are divided into two major language families. Along the way are C-based programming languages, such as JavaScript, JAVA, etc. These languages ​​are very similar in function calling, program statement writing, and loop control. The other is programming languages ​​headed by BASIC, such as FOXPRO, VBSCRIPT, etc. These languages ​​also have similar function calls, program statement writing and loop control, but are different from the C language system. Therefore, if you started with QBASIC before, it is best to brainwash before learning C language. Do not apply the methods and ideas of learning BASIC to C.

At this point, I think everyone must have a perceptual understanding of the C language! Let’s sublimate it a little more and get in touch with it intimately in all aspects. Learning C language must start from the following four points. In other words, as long as you can master these four points, you are basically done.

1. Read more code after getting started

After you have a certain foundation, you must read more other people's codes. Pay attention to the algorithms and data structures in your code. After all, the key points after learning C are algorithms and data structures. When it comes to data structures, pointers are an important part of it. Most data structures are built on pointers, such as linked lists, queues, trees, graphs, etc., so only by learning pointers well can you truly learn C well. You should also pay attention to other aspects, such as the naming of variables, the usage of library functions, etc. Some library functions are frequently used. The usage of these functions must be kept in mind.

2. Do it yourself

Programming is a practical job, and it is impossible to just talk without practicing. When you first start learning, you can practice more exercises in the book. For things you don't understand, the best way is to write a small program and experiment with it, which can leave a deep impression on yourself. In the process of doing it yourself, you must constantly correct your bad programming habits and misunderstandings. After you have a certain foundation, you can try to make up some small games and follow them as a practice. When the foundation is very solid, you can compile some things about data structure. After that... learn assembly and hardware knowledge.

3. Choose a good compiler

GCC or VS are both options.

4. About developing good programming habits

(1) There should be comments after more complex codes. If there is a bunch of code, it will be impossible for others to understand your code, and it will not be conducive to finding errors. Unless you keep making stuff up for yourself. What can be explained clearly in the code must be reflected in the code. For example, when naming variables and functions, try to explain what they are used for.

(2) Note that the nesting of statements cannot be too long. Generally speaking, there should be less than 8 tabs in a piece of code. Simply put, there are up to 8 nested statements. For newbies, the standard goes even lower. A good habit is to keep the main function as short as possible. I often see other people's code with only a few lines of main function and a few function calls, but all definitions are outside the main function. This firstly reduces the nesting within the main function, and secondly makes it simpler and easier to read.

(3) Pay attention to the choice of statements. It's not that you use if loops for branch statements or while and for. Switch and do while statements are also used where appropriate. In some cases, the switch statement is more concise and clear than the if statement, and do while has one less loop than while.

Many people find it difficult to learn C language. They often ask me the same question: How to learn C language? I am a teacher and have developed programs for many years. Like many people who are just starting out, I learned the first computer The language is C language. After these years of development, I deeply realize how important C language is to a programmer. If you don’t understand C language, it almost sounds ridiculous if you want to write low-level programs. If you don’t understand C language, you want to write Excellent and efficient program, this is simply a fantasy. Why is C language so important?

First: The grammatical structure of C language is very concise and exquisite, and the programs written are also very efficient, making it easy to describe algorithms. Most programmers are willing to use C language to describe the algorithm itself, so if you want to make achievements in programming , you must learn it.

Second: C language allows you to go deep into the bottom of the system. Which operating system do you know that is not written in C language? All windows, Unix, Linux, Mac, os/2, there is no one inside or outside. If you don’t understand How can C language penetrate deeply into these operating systems? Let alone write their kernel programs.

Third: Many new languages ​​are derived from C language, C++, Java, C#, J#, perl... which one is not? Mastering C language can be said to have mastered many languages. After simple learning, you can These new languages ​​can be used to develop. This once again verifies that C language is an important foundation for programming. Also, let me say one more thing: even if programmers are now being recruited, many exams test C language. If you want to join the IT industry, you must master C language.

Guess you like

Origin blog.csdn.net/weixin_50843918/article/details/132998950