I am a windows programmer, and the language I use is C. I know a little about other languages, but I am not good at them. Perhaps the first thing for beginners is to choose a programming language. Of course, this is not what I want to talk about today. Each language has its own professional field and level. Of course, I'm a stranger to other non-C languages, and I won't speak any other languages from the standpoint of C. Well, at first,
C language is an early computer language, which was originally born to provide a working language based on UNIX system. However, more and more people have discovered its advantages and potential. C itself is close to the bottom. Suitable for developing system software and even operating system. Personally, it is an intermediate language between high-level language and assembly language. C language is a structured language (I think it mainly refers to its control structure, such as if if-else while for, etc. ). C programming has mentioned "top-down, step by step". Function is an atomic function module. Modularity is very important for large programs. There is a saying that "high-quality procedures are first discussed and communicated with people, and then the efficiency of implementation". Of course, I personally think that any program writer should develop a specific way of thinking and think about the realization of the program with the way of thinking of the program. The premise is to have enough understanding of the underlying computer technology. Otherwise, I think it is difficult to study, and everything is a question of thinking. By standard, C should be regarded as a member of the high-level language camp. But many programmers who have experience in developing C language usually affectionately call C an intermediate computer language between low-level language and high-level language. Of course, it is not because C is inferior to a high-level language, but because C has both the structure and understandability of a high-level language and the high efficiency of a low-level language. At the same time, C has good portability. We should know that the closer we are to the hardware, the more the language close to the bottom depends on the hardware environment, which is what we call device dependence. C good. Speaking of which, we analyze C from another angle. Of course, each language has its own advantages and disadvantages, and so does C. For example, from the perspective of high-level languages and top-level technologies, the biggest drawback of C is the separation of data and algorithms. For example, for a program with thousands or even tens of thousands of lines of code, if I modify the data, for example, I add a field to the structure, my whole program may have to be changed, which greatly reduces the reusability of the program and greatly prolongs the development cycle. But from the bottom, this is also the advantage of C. Why should I say this? I personally think that when solving and realizing a small problem, we can write a general module to deal with different data. Of course, for example, we can write some common algorithms according to the data structure. During development, we can directly insert pre-written modules into our programs. Doesn't this also greatly shorten the development cycle? Beginners can write a custom library according to their own needs. Well, I have misunderstood some things. Please point out that communication is very important, provided that you keep a calm mind. Let me talk about the focus of this problem, that is, how to learn C language, which is for beginners.
Theme section:
Some people may say: I still need you to teach and learn. Who hasn't been to school? In fact, what I want to say today is to analyze and explain the difficulties in the process of learning C language from the perspective of an experienced person. Of course, I will also explain more specific issues (personal views). I have been emphasizing my personal point of view. I want you to understand that it may be difficult for you to reach a unified opinion on the same issue. I hope you are polite when you criticize.
What books should beginners read:
Before learning C language, you should first choose a textbook. For beginners, I personally don't recommend reading e-books, but it is better to buy paper books to study. For example, the famous C Programming is very good, especially the second edition. I've seen it, too. It's more suitable for beginners in China. The book gives a comprehensive and systematic explanation of the grammatical structure of C. The language elements that make up C include: data type, supported operators, and identifiers (the names given by programmers according to the naming rules are used for variable names, function names, macro names, etc. ), keywords (words used by the compilation system to realize the internal functions of C, such as going to goto, breaking, etc. ), etc. After reading this book, you can basically write some simple small programs, of course, programs under DOS. If you want to learn more about C, you can read the book C Traps and Defects. The author who wrote this book works in Bell. He is very proficient in C and should be regarded as a master. If you don't want to go deep into C for the time being, that's fine, because you can use C as a programming tool at this time. All you have to do is write more code to familiarize yourself with the C language. Experience is very important. "Experience is the only way to test the truth." Of course, you can't talk on paper. If you have too much development experience, you will know that the code you originally imagined on paper or computer will be realized, and eventually you will find that many places are unreasonable, which you never imagined before. In the process of learning C for beginners, for example, you will learn C by reading C Programming, and you will have to complete exercises after learning each chapter. This is to test what you have learned and see how your application ability is. Especially the topic of programming is very interesting. If you don't understand anything, you can go back to the explanation in the book. If you don't explain or still don't understand, you can ask others and communicate with them. Bbs, QQ or Google until you figure it out. When you finally solve the problem, I bet you must be very excited or more excited. At this time, knowledge is already in your brain.
Here I recommend some good books about C language to you:
C programming specification
The fourth edition of Encyclopedia of C language (I feel good personally, and there are also things mentioned in the C standard)
C and pointer
C programming language (classic)
If you want to read e-books, the books on it are easy to find on Google.
A preliminary understanding of C language;
For beginners, there will be too many questions because your knowledge is too small. Now I'm going to tell you something about C. The purpose is to give you a clear direction and arrange your study plan. Professionally, we are or will be programmers, and programmers will certainly develop programs. Let me explain the terminology of software development:
C, C++, ASM, BASIC and Java are all computer languages. There are many computer languages, so I won't talk about them.
Visual C++, Visual Basic, the development environment developed by Microsoft. Development environments include: compilers and library functions (every C language compiler supports standard libraries, and they will also expand their own libraries, so many programmers who have implemented library functions always don't use them at first when switching to different development environments after comparison, and will encounter many problems). Some resource templates and so on. Vision is vision, followed by language. Visual C++ supports both C and C++, and determines which compiler kernel to use according to the file extension.
What are "object-oriented" and "process-oriented"? In fact, they are two completely different programming ideas. C is a process-oriented language, while C++ is an object-oriented language. There is such a thing as "class" in object-oriented language. There is no such thing in C language. An object is an instance derived from a class, and a class is like a template.
What is SDK? SDK is a software development toolkit. It refers to a wide range. Generally speaking, everything that can be related to the software development process belongs to it, such as library files, reference materials and interface functions. Of course, language should also belong to it.
DDK is a device driver development toolkit.
Turbo C: This is an exquisite C language compiler.
Theoretically, any language can run on any operating system, provided that the operating system supports it, which is what we call application programming interfaces, such as window API. In fact, the interface functions defined by Microsoft are used to realize some internal functions of Windows. The description terms of some objects are different on different platforms. For example, "call" under Windows is often called "call" and "return" is called "return".
What is an algorithm? First of all, you just need to know that an algorithm is actually a piece of code that operates on specific data. You can also think of it as a general term for the methods and steps taken to solve problems. For the basic C program, it is actually composed of data and algorithms.
What is a "data structure"? If you want to explain it systematically, you need a book called Data Structure. Simply put, it is the way that the data to be processed by the program is stored and organized in memory, which is divided into physical structure and logical structure. Logical structure is the brain image that we get after abstraction.
What is "function library"? They are stored in the form of files, which are a set of predefined functions that can be directly called by our programs. Of course, the premise is to include its header file (the prototype declaration of the library function). These functions are combined into. During static connection. There is also a library in Windows called Dynamic Link Library (DLL).
GUI: That is the "graphical user interface", which is what we see on Windows. It exists in the display area in the form of menu bar, scroll bar and window.
GDI: graphics device interface, from the programmer's point of view, GDI is actually composed of hundreds of functions, data forms and some related data structures.
The whole process of learning C language:
Think about it. In fact, to learn C language, we must first learn the basic grammar of C language, which is the component of learning C language. Part of it, part of it. Knowledge should be consolidated bit by bit. I assume that you learn C language by reading C Programming. I think you should take a closer look at C programming first. In this way, you should be able to have a clear understanding of the whole book and the overall structure of C language. Don't think that learning is just reading a book. You should learn to take notes. In the process of taking notes, you are actually learning, from analyzing, understanding and summarizing knowledge to writing it down in your own way of thinking. The whole process is to abstract the knowledge in the book into your own head. Personally, I feel that the learning effect is very good. Ask if you don't understand. Communicate with others more, think more, and think more when encountering problems. You really can't figure out what the problem is. Ask others now, don't ask others directly if you don't understand. That won't do you much good. In fact, you should learn to arrange a study plan that suits you. I roughly estimate that if you can spend 4 hours quietly and study hard every day, you should be able to master C language within 30 days. In fact, you spend most of your study time reading books, not facing the computer. Before debugging your code, write down the core code on paper and analyze it: the module of the program (which can be a function or multiple functions) is realized by several functions, and the interface is encapsulated. Which data structure is more suitable? The key is the algorithm. It is best to minimize the number of lines of code before releasing the final program. Don't just want to write more code. Too much code is a burden to the program. You can download a file (chm, a classic example of C language) on the Internet, which contains about hundreds of classic examples. Each example is a typical application of a part of C language. Take time to study all the sample codes in this file, and you'd better improve the code yourself. Solve it in your own way. In the future, you will find that when you write some applications, you often have some algorithms. Will involve the example I mentioned earlier. Finally, I think I can write C language standard functions, such as strcpy (); strlen(); strcat(); It is best not to rely too much on library functions.
Difficulties in learning C language:
Now I should talk about a key link. Many netizens say that learning C language is difficult. I think some parts of C are more complicated and difficult to understand. Of course, after you have rich development experience, this is no longer a problem. Next, I will personally explain what I think is difficult to learn when learning C. If it is not correct, please point out:
Appearance of pointer:
I think it is very difficult for many beginners to learn the chapter of pointer, so I will explain this special data type of pointer with my own ideas.
Basic variables may not be difficult for everyone to understand, because they store constants of the same type. In fact, a pointer is also a variable. However, this variable is a little different from the basic variable. Then you ask: What's the difference? I tell you, simply understand, ordinary variables actually store constants of the same type, while pointer variables store "the first address of variables of the same type". Can you understand this? A simple explanation, but without losing the essence. This is a fact. If you don't understand "the first address of variables of the same type", I can give you a vivid description:
Floating variable; //Declare a variable of single precision real number type.
At this point, the compiler has allocated memory space to the variable, and the structure is as follows:
__________
| | 100 1
| -
| | 1002
| -
| | 1003
| -
| | 1004
| -
This is the storage structure of variables. The floating point under bit 16 occupies 4 bytes, and the memory address is linearly encoded. We can easily see that the first address of a Variable is the address of its first cell, 100 1. Ok, keep looking down:
Floating point * pointer = & variable; //Declare a pointer to a variable.
_________
| 100 1 | This is the memory structure of the pointer.
|_______|
Our program can be executed like this:
Variable =1.0;
Assigning values directly to variables is called direct access.
You can also do this:
* pointer =1.0;
You can also assign values through pointer variables. The front * is an indirect operation symbol, which means to find the memory unit that stores the address identification inside the pointer, that is, the variable. At this point, the allocation is achieved through indirect access. It can be described as follows:
_ _ _ _ _ _ (pointing to a variable) _ _ _ _ _ _ _
| Pointer |-> changeable
- -
The above should be the basic explanation of pointer implementation. Many excellent programmers say that pointers are the essence of C language. Indeed, many excellent programmers rely heavily on pointers when writing programs because it is convenient. In fact, the object accessed by the pointer is infinite, provided that we know the memory address. Therefore, pointers are unsafe, so try to use them as little as possible when developing network programs. Let's look at the pointers in the array.
Pointers in the array:
Simply explain the array, array structure is widely used in C, in fact, the most commonly used array is char type, which is mainly used for string operation. In fact, an array is a "finite collection of variables of the same type". I think this should be easy to understand. The array occupies consecutive memory cells (with consecutive addresses) in the memory to store each element in the array. The array is a pre-allocated memory cell with a specified length. For array elements. It does not support dynamic memory allocation. In order to uniquely identify the array in memory, two identifiers are needed: the entry address (function name) and the end tag ("\0"). Some languages do not support the closing tag of strings such as C, so they must declare another variable to identify the subscript of the closing element. This array name is actually the first cell in this group of memory cells. His address is the entry address of the whole array. At this time, it is necessary to understand that the array name is a pointer, and it is no problem to understand. It is true that it is not allowed to change the address of the array name during the specific operation, and it does not meet the actual requirements. Therefore, we can understand that the array name is const pointer (pointer constant). We can do this:
Int array [10];
Int * pointer;
Pointer = array;
for(I = 0; I< 10; ++i)
Pointer = = I;;
The code above should be fine. Pointers of the same type are fully qualified for the task of array names. No problem at all, it can run well. Of course, we can further write code like this:
keep
for(I = 0; I< 10; ++i)
Pointer = I;;
change into
for(I = 0; I< 10; ++i, pointer++)
* pointer = I;;
Sorry, I can't remember clearly whether the pointer++operation is the address+1 or the position of an element is moved back. If the address is+1, the above code will be changed to:
for(I = 0; I< 10; ++i, pointer +sizeof(int))
* pointer = I;;
It is more convenient if the array type is char, because the string has an end tag ('\0') after the end element. The following is a simple code, using the char pointer:
char * my_strcpy(char * dst,const char * src)
{
char * cp = dst
while(* cp++ = * src++); //Pay attention to the priority and combination of operators.
Return (daylight saving time); //Returns the newly passed pointer.
}
The above code realizes the function of transferring characters to copy. Isn't the code very concise? If you don't need to move memory blocks, you can sort them by exchanging pointers (memory addresses), and its efficiency should be very objective. Add: Make sure that the pointer itself and the variable pointed by the pointer are not a unit.