C
eBook - ePub

C

From Theory to Practice, Second Edition

George S. Tselikis, Nikolaos D. Tselikas

  1. 696 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

C

From Theory to Practice, Second Edition

George S. Tselikis, Nikolaos D. Tselikas

Book details
Book preview
Table of contents
Citations

About This Book

This easy-to-use, classroom-tested textbook covers the C programming language for computer science and IT students. Designed for a compulsory fundamental course, it presents the theory and principles of C. More than 500 exercises and examples of progressive difficulty aid students in understanding all the aspects and peculiarities of the C language. The exercises test students on various levels of programming and the examples enhance their concrete understanding of programming know-how. Instructor's manual and PowerPoint slides are available upon qualifying course adoption

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on ā€œCancel Subscriptionā€ - itā€™s as simple as that. After you cancel, your membership will stay active for the remainder of the time youā€™ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlegoā€™s features. The only differences are the price and subscription period: With the annual plan youā€™ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, weā€™ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is C an online PDF/ePUB?
Yes, you can access C by George S. Tselikis, Nikolaos D. Tselikas in PDF and/or ePUB format, as well as other popular books in Computer Science & Information Technology. We have over one million books available in our catalogue for you to explore.

Information

Publisher
CRC Press
Year
2017
ISBN
9781351796439
Edition
2

1 Introduction to C

Before getting into the details of C language, this chapter presents, in brief, its history, evolution, strengths, and weaknesses. Then, weā€™ll discuss some basic concepts that weā€™ll need in order to write our first program.

History of C

The C language was developed at Bell Labs in the early 1970s by Dennis Richie and others. At that time, the Unix operating system, also developed at Bell Labs, was written in assembly language. Programs written in assembly are usually hard to debug, maintain, and enhance, and Unix was no exception. Richie decided to rewrite Unix code in another language that would make the execution of these tasks easier. He named the language C because it was the evolution of an earlier language written by Ken Thompson, called B. The C language continued to evolve during the 1970s, and since then, it has been used by thousands of programmers for a wide variety of applications.

The ANSI Standard

The rapid expansion of the C language and its increased popularity led many companies to develop their own C compilers. Due to the absence of an official standard, their development relied on the bible of C programmers, the legendary K&R book, written by Brian Kernighan and Dennis Ritchie in 1978.
However, the K&R book was not written in the precise way that a standard requires. Features that were not clearly described could be implemented in different ways. As a result, the same program could be compiled with one C compiler and not with another. In parallel, the C language continued to evolve with the addition of new features and the replacement or obsolescence of existing ones.
The need for the standardization of C language became apparent. In 1983, the American National Standard Institute (ANSI) began the development of the C standard that was completed and formally approved, in 1989, as ANSI C or Standard C. In 1990, the ANSI C standard was adopted by the International Standards Organization (ISO) as ISO/IEC 9899:1990. This standard describes precisely the features, characteristics, and properties of the C language, and every C compiler must support it.
The addition of some new features to the ANSI standard during the late 1990s led to a new standard called C99. C99 was further enriched with new features, leading to the publication of the C11 standard. This book describes the C language based on the ANSI/ISO C standard.

Advantages of C

Despite the emergence of many programming languages, C still remains competitive and popular in the programming world for several reasons, such as the following:
  1. It is a flexible language, which can be used for the development of different kinds of applications, from embedded systems and operating systems to industrial applications. For example, weā€™ve used C in the area of communication networks for the development of network protocols and the support of network services.
  2. A C program is executed very quickly.
  3. It is a small language. Its vocabulary consists of a few words with special meanings.
  4. It is portable, meaning that a C program may run under different operating systems.
  5. It supports structural programming, meaning that a C program may contain functions to perform several tasks.
  6. It is a language very close to the hardware and it can be used for systems programming.
  7. Every C compiler comes with a set of ready-to-use functions, called C standard library. The use of these library functions saves considerable programming effort.
  8. Thanks to the popularity of the C language, there are many C compilers available; some of them free of charge.
  9. Learning C will help you to learn other languages. For example, getting familiar with C is the first step toward object-oriented programming. Most of the C features are supported in several object-oriented languages, like C++, Java, and C#.

Disadvantages of C

  1. Because the C language does not impose many restrictions on the use of its features, it is an error-prone language. When writing a C program, be cautious because you may insert bugs that wonā€™t be detected by the compiler.
  2. C supports only single-thread flow; it does not support multithread programming, parallel operation, and synchronization.
  3. Although C is a small language, it is not an ā€œeasy-to-useā€ language. C code can be very hard to understand even if it consists of a small number of lines. After reading this book, check out the International Obfuscated C Code Contest (http://www.ioccc.org) to get a feeling.
  4. C is not an object-oriented language; therefore, it does not support object-oriented features.

C Program Life Cycle

The life cycle of a C program involves several steps: write the code, compile the code, link the object code produced by the compiler with any code needed to produce the executable file, and run the program. Usually, a C compiler provides an integrated development environment (IDE) that allows us to perform this set of operations without leaving the environment.

Writing a C Program

To write a C program, we can use any available text editor. An editor is often integrated with the compiler. The source code must be saved in a file with extension .c. When the size of the code is very large, it is a common practice to divide the code into several files, in order to facilitate tasks like testing and maintenance. In such cases, each file is compiled separately.

Our First C Program

Our first program will be a ā€œrockā€ version of the program that most programmers begin with. Instead of the classical ā€œHello worldā€ message, our first program displays on the screen the classical song of Ramones, Hey Ho, Letā€™s Go. Play it loud, and letā€™s go ā€¦
 #include <stdio.h> int main(void) { printf("Hey Ho, Let's Go\n"); return 0; }
The following sections explain the significance of each program line.

The #include Directive

The #include directive instructs the compiler to include the contents of the stdio.h file into the program before it is compiled. Regarding syntax, directives always begin with a # character and do not end with a semicolon ; or some other special marker.
The stdio.h file and other files contain information about the standard library functions. The typical extension is .h and they are called header files. These files are supplied with the compiler. For example, as shown in Appendix C, the stdio.h (standard input output) file contains declarations of data input and output functions, and because of that, it is almost always included in a program. An included file may also contain #include directives and include other files. In general, when you are using a standard library function, you must include the header file that contains its declaration. The order of their inclusion does not matter. When you get familiar with the C language, you may edit your own header files and include them in your programs.
When the program is compiled, the compiler searches for the included files. The searching rules depe...

Table of contents

  1. Cover
  2. Half Title Page
  3. Title Page
  4. Copyright Page
  5. Dedication
  6. Contents
  7. Preface
  8. Acknowledgments
  9. About the Authors
  10. Chapter 1 Introduction to C
  11. Chapter 2 Data Types, Variables, and Data Output
  12. Chapter 3 Getting Input with scanf()
  13. Chapter 4 Operators
  14. Chapter 5 Program Control
  15. Chapter 6 Loops
  16. Chapter 7 Arrays
  17. Chapter 8 Pointers
  18. Chapter 9 Characters
  19. Chapter 10 Strings
  20. Chapter 11 Functions
  21. Chapter 12 Searching and Sorting Arrays
  22. Chapter 13 Structures and Unions
  23. Chapter 14 Memory Management and Data Structures
  24. Chapter 15 Files
  25. Chapter 16 The Preprocessor
  26. Chapter 17 Building Large Programs
  27. Chapter 18 Introduction to C++
  28. Chapter 19 Introduction to Java
  29. Chapter 20 Review Exercises
  30. Appendix 1 Precedence Table
  31. Appendix 2 ASCII Table
  32. Appendix 3 Library Functions
  33. Appendix 4 Hexadecimal System
  34. Index
Citation styles for C

APA 6 Citation

Tselikis, G., & Tselikas, N. (2017). C (2nd ed.). CRC Press. Retrieved from https://www.perlego.com/book/2193051/c-from-theory-to-practice-second-edition-pdf (Original work published 2017)

Chicago Citation

Tselikis, George, and Nikolaos Tselikas. (2017) 2017. C. 2nd ed. CRC Press. https://www.perlego.com/book/2193051/c-from-theory-to-practice-second-edition-pdf.

Harvard Citation

Tselikis, G. and Tselikas, N. (2017) C. 2nd edn. CRC Press. Available at: https://www.perlego.com/book/2193051/c-from-theory-to-practice-second-edition-pdf (Accessed: 15 October 2022).

MLA 7 Citation

Tselikis, George, and Nikolaos Tselikas. C. 2nd ed. CRC Press, 2017. Web. 15 Oct. 2022.