Example: bachelor of science

An Introduction to the C Programming Language and …

An Introduction to the C Programming Languageand Software DesignTim BaileyPrefaceThis textbook began as a set of lecture notes for a first-year undergraduate software engineeringcourse in 2003. The course was run over a 13-week semester with two lectures a week. The intentionof this text is to cover topics on the C Programming Language and introductory software design insequence as a 20 lecture course, with the material in Chapters 2, 7, 8, 11, and 13 well served bytwo lectures apiece. Ample cross-referencing and indexing is provided to make the text a servicablereference, but more complete works are recommended. In particular, for the practicing programmer,the best available tutorial and reference is Kernighan and Ritchie [KR88] and the best in-depthreference is Harbison and Steele [HS95, HS02].

This textbook began as a set of lecture notes for a first-year undergraduate software engineering course in 2003. The course was run over a 13-week semester with two lectures a week. The intention of this text is to cover topics on the C programming language and introductory software design in

Tags:

  Lecture, Notes, Programming, Lecture notes

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of An Introduction to the C Programming Language and …

1 An Introduction to the C Programming Languageand Software DesignTim BaileyPrefaceThis textbook began as a set of lecture notes for a first-year undergraduate software engineeringcourse in 2003. The course was run over a 13-week semester with two lectures a week. The intentionof this text is to cover topics on the C Programming Language and introductory software design insequence as a 20 lecture course, with the material in Chapters 2, 7, 8, 11, and 13 well served bytwo lectures apiece. Ample cross-referencing and indexing is provided to make the text a servicablereference, but more complete works are recommended. In particular, for the practicing programmer,the best available tutorial and reference is Kernighan and Ritchie [KR88] and the best in-depthreference is Harbison and Steele [HS95, HS02].

2 The influence of these two works on this text isreadily apparent sets this book apart from most introductory C- Programming texts is its strong emphasison software design. Like other texts, it presents the core Language syntax and semantics, but it alsoaddresses aspects of program composition, such as function interfaces (Section ), file modularity(Section ), and object-modular coding style (Section ). It also shows how to design for errorsusingassert()andexit()(Section ). Chapter 6 introduces the basics of the software designprocess from the requirements and specification, to top-down and bottom-up design, to writingactual code. Chapter 14 shows how to write generic software ( , code designed to work with avariety of different data types).

3 Another aspect that is not common in introductory C texts is an emphasis on bitwise course for which this textbook was originally written was prerequisite to an embedded systemscourse, and hence required an Introduction to bitwise manipulations suitable for embedded systemsprogramming. Chapter 12 provides a thorough discussion of bitwise Programming full source code for all significant programs in this text can be found on the web at Given the volatilenature of the web, this link may change in subsequent years. If the link is broken, please email I will attempt to rectify the textbook is a work in progress and will be refined and possibly expanded in the future. Nodoubt there are errors and inconsistencies both technical and grammatical although hopefullynothing too seriously misleading.

4 If you find a mistake or have any constructive comments pleasefeel free to send me an email. Also, any interesting or clever code snippets that might be incorporatedin future editions are most Bailey (July 12, 2005)TODO:- complete Chapter 16- complete appendices- complete the indexiContentsPrefaceiContentsii1 Programming and Programming The C Programming AFirstProgram .. VariantsofHelloWorld .. ANumericalExample .. AnotherVersionoftheConversionTableExampl e .. Organisation of the Text ..62 Types, Operators, and Identifiers .. Types .. Constants .. Symbolic Constants .. Arithmetic Operations .. Relational and Logical Bitwise Assignment Operators.

5 Type Conversions and 163 Branching and If-Else .. :Conditional Do-WhileLoops .. ForLoops .. BreakandContinue .. 234 Function Prototypes .. Function Benefits of Functions .. TheStandardLibrary .. 325 Scope and Local Scope and Automatic External Scope and Static ThestaticStorage Class Scope Resolution and Name Summary of Scope and Extent Modular Programming : Multiple File 396 Software Requirements and Top-down and Bottom-up Pseudocode CaseStudy:ATic-Tac-ToeGame .. Requirements .. Specification.

6 Program Flow and Data Bottom-Up Top-Down Benefits of Modular 487 WhatisaPointer?.. PointerSyntax .. Pass By PointersandArrays .. PointerArithmetic .. ReturnValuesandPointers .. PointerstoPointers .. Function 578 Arrays and Array CharacterArraysandStrings .. ArraysofPointers .. Multi-dimensionalArrays .. 659 Dynamic DifferentMemoryAreasinC .. Standard Memory Allocation Dynamic Memory Example:AnExpandableArray .. 75iii10 The C File Symbolic Constants .. Macro Basics .. More Macros .. More Complex Conditional Compilation.

7 8411 Structures and Operations on Arrays of Structures .. Self-Referential Object-Oriented Programming Expandable Array 9712 Bitwise Binary Representations .. Bitwise AND, OR, XOR, and Right Shift and Left Operator Common Bitwise 10313 Input and Formatted Formatted Output:printf().. Formatted Input:scanf().. String File Opening and Closing Standard IO .. Sequential File Random Access File Command-Shell Command-Line 11414 Generic Basic Generic Design: Typedefs, Macros, and Advanced Generic Design:void *.. Case Study: Expandable Type Specific Wrapper Case Study:qsort().

8 123iv15 Data Efficiency and Time Linked Circular Binary Hash 13516 C in the Real Further ISO C Topics .. Traditional Make Beyond the C Standard Interfacing With Mixed Language Memory Interactions .. Advanced Algorithms and Data 141A Collected Style Rules and Common StyleRules .. Common 142B The Compilation Process143 Bibliography144 Index146vChapter 1 IntroductionThis textbook was written with two primary objectives. The first is to introduce the C program-ming Language . C is a practical and still-current software tool; it remains one of the most popularprogramming languages in existence, particularly in areas such as embedded systems.

9 C facilitateswriting code that is very efficient and powerful and, given the ubiquity of C compilers, can be easilyported to many different platforms. Also, there is an enormous code-base of C programs developedover the last 30 years, and many systems that will need to be maintained and extended for manyyears to second key objective is to introduce the basic concepts of software design. At one-level thisis C-specific: to learn to design, code and debug complete C programs. At another level, it is moregeneral: to learn the necessary skills to design large and complex software systems. This involveslearning to decompose large problems into manageable systems of modules; to use modularity andclean interfaces to design for correctness, clarity and Programming and Programming LanguagesThe native Language of a computer is binary ones and zeros and all instructions and data mustbe provided to it in this form.

10 Native binary code is calledmachinelanguage. The earliest digitalelectronic computers were programmed directly in binary, typically via punched cards, plug-boards,or front-panel switches. Later, with the advent of terminals with keyboards and monitors, suchprograms were written as sequences of hexadecimal numbers, where each hexadecimal digit representsa four binary digit sequence. Developing correct programs in machine Language is tedious andcomplex, and practical only for very small order to express operations more abstractly,assemblylanguages were developed. These lan-guages have simple mnemonic instructions that directly map to a sequence of machine languageoperations. For example, theMOVinstruction moves data into a register, theADDinstruction addsthe contents of two registers together.


Related search queries