Advice on learning C Language

Source: Internet
Author: User
Tags netbeans

Why C language learning?

Why study and use C language? Why should I learn a programming language that may be older than myself?

Choosing a programming language is the most important goal of "Why to learn". If the purpose is unclear, you cannot learn well. This is why many students and friends do not understand the required C language in college. Because the purpose of learning is unclear, learning certainly has no motivation. Another reason is that C language is a very practical engineering language. It is not from a university college in a certain Institute, but is actually generated from the project needs. It is popular with the rise of Unix, simple and clear semantics, powerful functions, but not bloated, concise and not overly simple, is really a must-have friend for home travel work and study.

One of the advantages of C language compared with C ++ is the principle of least surprise. One is one, two, and two. It will not generate some inexplicable additional products in private. Use C ++ as an example. For example, if a function prototype void PassWithClassValue (COneClass clsParam1) is used, anyone who knows a little about C ++ will know that if you have not implemented the COneClass copy constructor, the compiler will kindly help you implement one, and when calling this function PassWithClassValue, it secretly calls the copy constructor to generate a temporary object for passing as a parameter. In some cases, for example, when writing an operating system that requires performance optimization, these self-righteous things are very evil.

C language itself only provides necessary language features. Other complex functions, such as file processing and mathematical computing, are provided in the form of library functions, and even "mandatory" functions such as malloc and free, it is also provided in the form of standard library functions, rather than as the core of the C language. In the beginning of the famous "K & R", we mentioned that for can actually be done through while, but for can be more concise and explicit, C language for is not necessary. In other programming languages, Lua inherits the Concise Design Philosophy of C language, and even almost essential keywords such as continue have been refused to join, lua maillist and wiki mentioned the issue of continue. Lua language maintainer considers that continue is not necessary for Lua and does not consider adding this keyword in subsequent versions. This concise philosophy also makes C language portable and portable, and also makes many embedded systems still use C language as the main programming language.

The Java language has a slogan: "One-time writing, running everywhere", that is, cross-platform. In fact, the C language has almost reached the "one-time compilation, everywhere compilation" level since the early days. After ANSI unified the C language standard in 1989 (called C89 ), as long as the compiler on a specific platform fully implements the C89 standard and your code does not use some special extensions (GCC and Microsoft both have their own compiler-specific extensions ), then the code can be compiled, and then implement the function libraries related to the operating system. porting the C language is very simple. You can use Lua as an example. Lua fully complies with the C89 standard and does not use any specific extensions. This ensures that Lua can be compiled and used by platforms with C language compilers. It is really interesting to compile A hardware platform that runs C language from A to Z.

C language is also a rare widely used language. For example, writing an operating system is very difficult. Only C ++ and assembly languages can be used. The C language can be used to write server software such as Apache and Nginx, or GUI programs such as GTK. The first version of most programming languages is implemented in C language. With the help of the "one-time compilation everywhere" mentioned above, the portability of these programming languages is guaranteed. In the Web development field, there are relatively few applications in C language, which is also a trade-off. Web development requires dynamic languages such as PHP, Ruby, and Python, which can be quickly released and modified, it can satisfy users' changing needs at most, which is also a weakness of C language. If the application fields of programming languages are arranged from hardware to management software and Web programs in a rough bottom-up arrangement, the C language is suitable for the field that is closer to the hardware at the underlying layer, emerging languages are more focused on areas close to end users such as high-level management or Web development. The popular hybrid development mode is to use the C language to write the underlying high-performance part of the Code or the background server code, while using dynamic languages such as Python for front-end development, give full play to their respective strengths.

When talking about the disadvantages of C language, it is often because it lacks this or that feature. For example, some people suggest adding GC, some people suggest adding parallel or concurrent support, some people have mentioned that there is no complete exception policy similar to C ++. Some of these features can be implemented through the introduction of third-party libraries, but the design philosophy of C language actually determines that it will not be as "very powerful" as C ++ ". Even if the features expected by some people are introduced, some people will still like the features that some people do not like. The current functions are sufficient for the C language application field, other features can be implemented in specific programming languages and interact with C-language programs through C APIs. No craftsman can use only one tool to complete his work. Different tools can be combined to complete the task faster and better.

When talking about the C language API, we will also introduce it a little. We know the windows operating system api or the Linux system api, or we want to write extension modules for Ruby and Python, function definitions in the C language form are the only choice. C language is like an intermediate layer or glue. If you want to mix functional modules implemented by different programming languages, C language is the best choice.

If you have mentioned so many advantages about the C language, it depends on your own judgment to learn whether the C language is suitable. For example, if you want to develop an embedded project or a server, or write a performance-related component. C language is a good choice. In addition, you can also intentionally use the C language thinking method in the use of C ++, draw on the C language concise and clear design ideas, the programming design level will be greatly improved.

C Language Learning Method

C language learning can follow the following reference sequence: Read reference books, read code, write and debug real programs, participate in discussions online, and study advanced topics.

The beginning of language learning is generally to read reference books. I suggest you read several classic books carefully and repeatedly, and read the books for hundreds of times ". The advantage of C language learning is that these books basically cover all aspects of the C language programming field, and will not be as confused as C ++, even after reading a pile of books, there are still such difficult traps.

1. Reference Books

You have listed a ticket on Douban. For more information, see http://book.douban.com/doulist/636329 /. In the following simple comment, it is best to refer to the listed order of reading order.

The C Programming Language. If you have enough funds, we recommend that you buy more books and store them in your office or home. Three words are used to describe it: Classic! Classic! Classic! This thin book with more than two hundred pages covers all aspects of the C language. It has never been used before and has never been used before. It cannot be described in any word.

The C Programming Language (K & R) contains a simple syntax parser, including how to implement malloc and a complete operating system directory browsing program, these programs are highly practical. It can be said that if you can learn any language to implement the above functions independently, it is basically an entry. Each section in the K & R book contains a lot of practical software development engineering experience worth exploring. Without some development experience, I can't see the content below these iceberg, for example, in the first chapter, we propose to use the full code writing method for teaching. in the book, the traps of C language or problems may be mentioned, but due to space limitations, it is very simple to write, it is difficult to understand. I am reading this book from words to words. I hope I can give some comments and share some blogs.

C programming language (version 2nd-New Version.

C traps and defects http://book.douban.com/subject/2778632/

C expert programming http://book.douban.com/subject/2377310/

These two books are also essential for learning and using C language. For example, C expert programming, we use two or three chapters to introduce the differences between arrays and pointers in C language, to some extent, these two books provide a detailed supplement to K & R skipped and are strongly recommended.

References in C Language. The previous books may be a little concise or focused on a specific topic, so it is not suitable to review the questions. This "C Language Reference Manual" can be viewed as a "Xinhua Dictionary" programmed in C language, which is comprehensive and authoritative. It also covers C99 content, keeping up with the trend of the times.

The following books can be used as a cross-cutting reference and are of great value. We also recommend that you buy them as well as make good books, such as friends, the books I have recommended are rated very high on douban or amazon, and they are repeatedly revised.

All the friends of C and pointer NLP (or C ++) know that this book even raises the pointer to a position equal to that of C language. In fact, it is also introduced from the beginning, it can also be used as a reference book for teaching.

C Standard Library? How Should strlen be implemented? Although many of the Code in the book is much different from the real C Standard Library (because the standard library needs to consider performance optimization, many functions have some specific trick), but the absolute value is worth reference.

495 C language problems you must know. If you want to apply for or recruit C-language programmers, you must refer to this book.

Linux C Programming one-stop learning workshop. Almost all the content in the book is made public on the Internet and the comments of the readers are modified. This is also a rare open attitude. We recommend that you buy one.

To learn C language, you must not only read books. You should practice the project requirements in the book (such as writing a directory browser) and the exercise questions in each chapter. This requires a lab environment. The following is a brief introduction to different operating systems.

2. Build a hands-on lab environment

I haven't investigated it. I don't know if I still use TurboC2.0 to program C language in my school. If I still use this combination, it would be too bad. Let's leave them alone.

The following describes the Integrated Programming Environments on different operating system platforms. Based on beginner's preferences and my personal preferences, we do not recommend using vim for programming on the command line and directly using IDE.

In Windows, we recommend that you use the Code: blocks. The biggest advantage of this software is that it comes with mingw-based GCC and GDB. As long as the software package is about 70 MB, it can fully support C ++ and C programming. Various functions (such as debugging functions) are also very powerful, and version updates are also relatively fast. Download a file with the mingw name. For example, the latest version is codeblocks-10.05mingw-setup.exe (the version may be different ). Home: http://www.codeblocks.org/

To develop a Windows operating system, you can download Visual C ++ 2010 Express.

Because Code: Blocks does not contain Windows programming header files (because there is no Windows SDK), you cannot write Windows OS-related interface applications or service programs. While VC ++ Express comes with these header files and programming libraries, although the functions are a little simple, it is basically enough for exercises. Home: http://www.microsoft.com/express/windows/

For students of computer science, we recommend that you use the Linux operating system, or use the Xubuntu operating system as the desktop and the combination of Netbeans and GCC (of course, you can also choose Code :: blocks ). In Xubuntu, you can run the apt-get install build-essential command to install gcc-related programs. You can compile C language programs under Terminal, but for ease of use, you can download the C ++ support package from the Netbeans website. Home: http://netbeans.org/features/cpp/index.html

If you use the Apple Mac system, there is no doubt that XCode is the perfect choice for programming. XCode can be downloaded free of charge on the Apple developer website, and XCode is also included in the IPhone SDK. Home: http://developer.apple.com/technologies/tools/xcode.html

If you do not have a proper programming environment at hand, you also need to experiment with some simple code, you can use the http://codepad.org/provided services, online programming run code.

In addition, we recommend that you apply for a github.com account. You can save your exercise code on gist.github.com without carrying a USB flash drive.

3. Network Resources

If you want to take ten minutes to understand the C language of the ins and outs, past and present, Wikipedia this page http://en.wikipedia.org/wiki/C_%28programming_language%29 is the best choice.

From Wikipedia, we can see that the C language is a imperative and structured paradigm programming language designed by Dennis Ritchie in 1972. The type is static weak type and needs to be explicitly defined. The latest international standard is C99. The design is mainly influenced by B, ALGOL68, assembly language, PL/I, and FORTRAN. The C language also affects a large number of programming languages, for example, C ++, Objective-C, C #, Java, Go, PHP, Python, and so on (I personally think PHP is the most affected by C, basically, programmers with C Programming basics can easily get started with PHP, except for the OO part of PHP ).

The Wikipedia entry has a lot of space to introduce the features that the author thinks are missing in C language, such as object-oriented, multithreading, GC, and Exception Handling. Of course, this is a bit of a flaw. If you need these features, you can use other programming languages. Another Introduction focuses on "undefined behaviors". Some of the results we take for granted are not clearly defined in the C language standards. Assuming what these behaviors should do, A bug may occur when the program is compiled and run using another compiler or different versions of the compiler.

Next, the Wikipedia entry talked about the use of C language. Although there are hundreds of programming languages, few of them can be called "system-level", and only Go can be called as a new language. Currently, it is unlikely that C language is fully used in large-scale software projects, but the core part can be fully built using C. Compared with the high price of C ++ development tools, C language-related free auxiliary development software is very rich, for example, splint and valgrind, many core databases are also very stable after long-term use.

Since C language supports a wide range of platforms and the compiler is relatively mature and reliable, many programming languages Choose C language as an intermediate layer, such as the Glasgow Haskell compiler.

Another way to find a lot of C language programming related information is "delicious bookmarks", by searching specific keywords (C + programming) can find a lot of resources worth mining http://delicious.com/search? P = c + programming. You can also refer to d1200.org C language classification http://www.dmoz.org/Computers/Programming/Languages/C/ compared to the delicious bookmarks timeliness performance almost, but the classification is more systematic, search is also easier.

Programmers are often lazy, and "tailism" and "copyism" are very popular and effective. When you are not very familiar with a function or keyword, you can see how others use them, it will be very enlightening. Here we introduce several common code search websites, the most commonly used is google codesearch: http://codesearch.google.com, you can search for specific keywords through different conditions and regular expressions. In addition, you can refer to the "articles with examples of C language" on Wikipedia, and the code is well written. You can also search for related projects on github.com. In the previous blog article I also introduced a site named ROMs code http://rosettacode.org/This site can find different programming languages for a specific problem solution, for learning is very convenient.

Learning programming also requires a lot of reading the classic code of famous artists, and learning Chinese and English requires a lot of reading the famous books. The high quality program of C language programming is "colorful banners dancing, crowded ", I suggest you look at the code of projects such as Lua, Sqlite, and Nginx. There is not much code, and the code quality is also high. In addition, you can look at the Linux kernel code. There are many books that can help you interpret it. For more information about how to read the Code, see Code Reading.

I have read a few books, written some code, and slightly read the code of others. I should use the C language to complete the problems encountered in real work, make C language truly your Swiss Army knife. Only when you often use the C language for programming, you often think about how to design an elegant and efficient system through C, in order to have a deeper understanding of the C language design philosophy.

You can also go to the http://stackoverflow.com to answer questions, browse other people's answers to the questions to learn, for example, this http://stackoverflow.com/questions/2054939/char-is-signed-or-unsigned-by-default introduces a C language on the char type of small traps.

In C language learning, you need to pay more attention to some difficulties, such as the differences between pointer and array, how to interpret complicated Type Definitions, how to correctly use pre-processing preprocessor and macro definitions. In fact, these contents are repeatedly mentioned in the previous books. If you study them step by step, it should not be a problem.

When C language is almost the same, you can also learn a dynamic language, such as Lua or Python, and try to mix Dynamic Language and C language in actual work projects, the power of one plus one is not only two, but two (laugh, haha ).

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.