C Programming Lecture Notes
Thông tin tài liệu:
Nội dung trích xuất từ tài liệu:
C Programming Lecture NotesKỹThuậtlậptrìnhCHVKTQSC Programming Lecture NotesThese notes are written based on the book The C Programming Language, by Brian Kernighan andDennis Ritchie, or K&R (The second edition was published in 1988 by Prentice-Hall, ISBN 0-13-110362-8.). The sections are cross-referenced to those of K&R, for the reader who wants to pursue amore in-depth exposition.Chapter 1: IntroductionChapter 2: Basic Data Types and OperatorsChapter 3: Statements and Control FlowChapter 4: More about Declarations (and Initialization)Chapter 5: Functions and Program StructureChapter 6: Basic I/OChapter 7: More OperatorsChapter 8: StringsChapter 9: The C PreprocessorChapter 10: PointersChapter 11: Memory AllocationChapter 12: Input and OutputChapter 13: Reading the Command LineChapter 14: Whats Next?Chapter 15: User-Defined Data StructuresChapter 16: The Standard I/O (stdio) LibraryChapter 17: Data FilesChapter 18: Miscellaneous C FeaturesChapter 19: Returning ArraysChapter 20: More About the PreprocessorChapter 21: Pointer Allocation StrategiesChapter 22: Pointers to PointersChapter 23: Two-Dimensional (and Multidimensional) ArraysChapter 24: Pointers To FunctionsChapter 25: Variable-Length Argument ListsChapter 1: IntroductionC is (as K&R admit) a relatively small language, but one which (to its admirers, anyway) wears well.Cs small, unambitious feature set is a real advantage: theres less to learn; there isnt excess baggagein the way when you dont need it. It can also be a disadvantage: since it doesnt do everything for you,theres a lot you have to do yourself. (Actually, this is viewed by many as an additional advantage:anything the language doesnt do for you, it doesnt dictate to you, either, so youre free to do thatsomething however you want.) 1KỹThuậtlậptrìnhCHVKTQSC is sometimes referred to as a ``high-level assembly language. Some people think thats an insult,but its actually a deliberate and significant aspect of the language. If you have programmed inassembly language, youll probably find C very natural and comfortable (although if you continue tofocus too heavily on machine-level details, youll probably end up with unnecessarily nonportableprograms). If you havent programmed in assembly language, you may be frustrated by Cs lack ofcertain higher-level features. In either case, you should understand why C was designed this way: sothat seemingly-simple constructions expressed in C would not expand to arbitrarily expensive (in timeor space) machine language constructions when compiled. If you write a C program simply andsuccinctly, it is likely to result in a succinct, efficient machine language executable. If you find that theexecutable program resulting from a C program is not efficient, its probably because of something sillyyou did, not because of something the compiler did behind your back which you have no control over.In any case, theres no point in complaining about Cs low-level flavor: C is what it is.A programming language is a tool, and no tool can perform every task unaided. If youre building ahouse, and Im teaching you how to use a hammer, and you ask how to assemble rafters and trussesinto gables, thats a legitimate question, but the answer has fallen out of the realm of ``How do I use ahammer? and into ``How do I build a house?. In the same way, well see that C does not have built-in features to perform every function that we might ever need to do while programming.As mentioned above, C imposes relatively few built-in ways of doing things on the programmer. Somecommon tasks, such as manipulating strings, allocating memory, and doing input/output (I/O), areperformed by calling on library functions. Other tasks which you might want to do, such as creating orlisting directories, or interacting with a mouse, or displaying windows or other user-interface elements,or doing color graphics, are not defined by the C language at all. You can do these things from a Cprogram, of course, but you will be calling on services which are peculiar to your programmingenvironment (compiler, processor, and operating system) and which are not defined by the Cstandard. Since this course is about portable C programming, it will also be steering clear of facilitiesnot provided in all C environments.Another aspect of C thats worth mentioning here is that it is, to put it bluntly, a bit dangerous. C doesnot, in general, try hard to protect a programmer from mistakes. If you write a piece of code which will(through some oversight of yours) do something wildly different from what you intended it to do, up toand including deleting your data or trashing your disk, and if it is possible for the compiler to compile it,it generally will. You wont get warnings of the form ``Do you really mean to...? ...
Tìm kiếm theo từ khóa liên quan:
Memory Allocation Data Structures Allocation Strategies Miscellaneous C Features Pointers To Functions Program StructureGợi ý tài liệu liên quan:
-
Ebook Eloquent JavaScript - A modern introduction to programming: Part 1
199 trang 33 0 0 -
Lecture Introduction to computing systems (2/e): Chapter 19 - Yale N. Patt, Sanjay J. Patel
28 trang 30 0 0 -
Ebook Introduction to algorithms (3rd edition)
1313 trang 27 0 0 -
Ebook The JavaScript way: A gentle introduction to an essential language - Part 1
128 trang 26 0 0 -
Ebook C - Answer Book (The C programming language)
214 trang 26 0 0 -
Lecture Data Structures: Lesson 38
71 trang 26 0 0 -
Lecture Data structures and algorithms: Chapter 1 - Introduction
41 trang 26 0 0 -
Lecture note Data visualization - Chapter 22
21 trang 24 0 0 -
335 trang 23 0 0
-
Ebook Introduction to algorithms (Second Edition)
429 trang 23 0 0 -
Lecture Data Structures: Lesson 41
18 trang 23 0 0 -
169 trang 23 0 0
-
Lecture Data Structures: Lesson 36
24 trang 22 0 0 -
Lecture Software construction - Lecture 8: Java implementation
17 trang 22 0 0 -
Lecture Algorithms and data structures: Chapter 28 - Graphs
31 trang 21 0 0 -
2624 trang 21 0 0
-
429 trang 20 0 0
-
Lecture Introduction to Programming: Lesson 28
33 trang 20 0 0 -
Lecture Data Structures: Lesson 32
16 trang 20 0 0 -
Lecture note Data visualization - Chapter 3
31 trang 20 0 0