0% found this document useful (0 votes)
4 views

Algorithms week 1

The document outlines the objectives and content of the ninth edition of 'C How to Program', focusing on recent developments in computing, the fundamentals of computer hardware and software, and the C programming language. It introduces key concepts such as data hierarchy, types of programming languages, and the C standard library. The document also discusses the organization of computers, the importance of programming, and the growing field of big data.

Uploaded by

mrymmslmyr
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Algorithms week 1

The document outlines the objectives and content of the ninth edition of 'C How to Program', focusing on recent developments in computing, the fundamentals of computer hardware and software, and the C programming language. It introduces key concepts such as data hierarchy, types of programming languages, and the C standard library. The document also discusses the organization of computers, the importance of programming, and the growing field of big data.

Uploaded by

mrymmslmyr
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

C How to Program

Objectives
Ninth Edition
• Learn about exciting recent developments in computing.
• Learn computer hardware, software and Internet basics.
Chapter 1 • Understand the data hierarchy from bits to databases.
Introduction to Computers • Understand the different types of programming
and C languages.
• Understand the strengths of C and other leading
programming languages.
• Be introduced to the C standard library of reusable
functions that help you avoid “reinventing the wheel.”

Copyright © 2022 Pearson Education, Inc. All Rights Reserved Copyright © 2022 Pearson Education, Inc. All Rights Reserved

Outline (1 of 2) Outline (2 of 2)
1.1 Introduction 1.8 Other Popular Programming Languages
1.2 Hardware and Software 1.9 Typical C Program-Development Environment
1.2.1 Moore’s Law 1.9.1 Phase 1: Creating a Program
1.2.2 Computer Organization 1.9.2 Phases 2 and 3: Preprocessing and Compiling a C
1.3 Data Hierarchy Program
1.4 Machine Languages, Assembly Languages and High-Level 1.9.3 Phase 4: Linking
Languages 1.9.4 Phase 5: Loading
1.5 Operating Systems 1.9.5 Phase 6: Execution
1.9.6 Problems That May Occur at Execution Time
1.6 The C Programming Language
1.9.7 Standard Input, Standard Output and Standard Error
1.7 The C Standard Library and Open-Source Libraries Streams

Copyright © 2022 Pearson Education, Inc. All Rights Reserved Copyright © 2022 Pearson Education, Inc. All Rights Reserved

1
1.1 Introduction (1 of 4) 1.1 Introduction (2 of 4)

• C is one of the world’s most senior computer programming languages and, • Introduce terminology and concepts that lay the
according to the Tiobe Index, the world’s most popular
groundwork for the C programming you’ll learn, beginning
• You’re probably familiar with many of the powerful tasks computers in Chapter 2
perform—in this textbook, you’ll get intensive, hands-on experience writing C
instructions that command computers to perform those and other tasks • Introduce hardware and software concepts
• Software (that is, the C instructions you write, which are also called code)
controls hardware (that is, computers and related devices) • Overview the data hierarchy
• C is widely used in industry for a wide range of tasks
– From individual bits (ones and zeros) to databases,
which store the massive amounts of data that
• Today’s popular desktop operating systems—Windows, macOS and Linux—
are partially written in C
organizations need to implement contemporary
applications such as Google Search, Netflix, Twitter,
• Many popular applications are partially written in C, including popular web
browsers (e.g., Google Chrome and Mozilla Firefox), database management
Waze, Uber, Airbnb and a myriad of others
systems (e.g., Microsoft SQL Server, Oracle and MySQL) and more

Copyright © 2022 Pearson Education, Inc. All Rights Reserved Copyright © 2022 Pearson Education, Inc. All Rights Reserved

1.1 Introduction (3 of 4) 1.1 Introduction (4 of 4)

• We’ll discuss the types of programming languages • Many development environments are available in which
you can compile, build and run C applications
• We’ll introduce the C standard library and various C-
based “open-source” libraries that help you avoid • In the past, most computer applications ran on
“reinventing the wheel” “standalone” computers (that is, not networked together)
• We’ll introduce additional software technologies that • Today’s applications can communicate among the
you’re likely to use as you develop software in your world’s computers via the Internet
career

Copyright © 2022 Pearson Education, Inc. All Rights Reserved Copyright © 2022 Pearson Education, Inc. All Rights Reserved

2
1.2 Hardware and Software (1 of 2) 1.2 Hardware and Software (2 of 2)
• Computers can perform calculations and make logical decisions • Computers process data under the control of sequences of instructions
phenomenally faster than human beings can called computer programs (or simply programs)

• Today’s personal computers and smartphones can perform billions of • Specified by people called computer programmers
calculations in one second—more than a human can perform in a • A computer consists of various physical devices referred to as hardware
lifetime – keyboard, screen, mouse, solid-state disks, hard disks, memory, DVD
• Supercomputers already perform thousands of trillions (quadrillions) drives and processing units
of instructions per second! • Computing costs are dropping dramatically due to rapid developments in
– As of December 2020, Fujitsu’s Fugaku is the world’s fastest hardware and software technologies
supercomputer—it can perform 442 quadrillion calculations per – Computers that might have filled large rooms and cost millions of dollars
second (442 petaflops)! decades ago are now inscribed on silicon computer chips smaller than a
fingernail, costing perhaps a few dollars each
– To put that in perspective, this supercomputer can perform in
one second almost 58 million calculations for every person on – Silicon-chip technology has made computing so economical that
computers and computerized devices have become commodities.
the planet! And supercomputing upper limits are growing quickly.
Copyright © 2022 Pearson Education, Inc. All Rights Reserved Copyright © 2022 Pearson Education, Inc. All Rights Reserved

1.2.1 Moore’s Law (1 of 2) 1.2.1 Moore’s Law (2 of 2)


• Every year, you probably expect to pay at least a little • Key executives at computer-processor companies NVIDIA and Arm
more for most products and services have indicated that Moore’s Law no longer applies
• Computer processing power continues to increase but relies on new
• The opposite has been the case in the computer and processor designs, such as multicore processors (Section 1.2.2).
communications fields
• Moore’s Law and related observations apply especially to
• Over the years, hardware costs have fallen rapidly – the amount of memory that computers have for programs,
• For decades, every couple of years, computer – the amount of secondary storage (such as hard disks and solid-
state drive storage) they have to hold programs and data, and
processing power approximately doubled inexpensively
– their processor speeds—that is, the speeds at which computers
• This trend often is called Moore’s Law execute programs to do their work.
– Named for Gordon Moore, co-founder of Intel and • Similar growth has occurred in the communications field
the person who identified this trend in the 1960s
Copyright © 2022 Pearson Education, Inc. All Rights Reserved Copyright © 2022 Pearson Education, Inc. All Rights Reserved

3
1.2.2 Computer Organization (1 of 5) 1.2.2 Computer Organization (2 of 5)
• Regardless of physical differences, computers can be • Memory Unit—This rapid-access, relatively low-capacity “warehouse”
envisioned as divided into various logical units or section retains information entered through the input unit, making it
immediately available for processing when needed.
sections
– The memory unit also retains processed information until it can
• Input Unit—This “receiving” section obtains information be placed on output devices by the output unit
(data and computer programs) from input devices and – Information in the memory unit is volatile—it’s typically lost when
places it at the other units’ disposal for processing the computer’s power is turned off
– The memory unit is often called either memory, primary memory
• Output Unit—This “shipping” section takes information or RAM (Random Access Memory). Main memories on desktop
the computer has processed and places it on various and notebook computers contain as much as 128 GB of RAM,
output devices to make it available outside the computer though 8 to 16 GB is most common. GB stands for gigabytes; a
gigabyte is approximately one billion bytes. A byte is eight bits. A
bit (short for “binary digit”) is either a 0 or a 1.

Copyright © 2022 Pearson Education, Inc. All Rights Reserved Copyright © 2022 Pearson Education, Inc. All Rights Reserved

1.2.2 Computer Organization (3 of 5) 1.2.2 Computer Organization (4 of 5)


• Arithmetic and Logic Unit (ALU)—This “manufacturing” section • Most computers today have multicore processors that
performs calculations (e.g., addition, subtraction, multiplication and economically implement multiple processors on a single
division) and makes decisions (e.g., comparing two items from the
memory unit to determine whether they’re equal)
integrated circuit chip
– Part of the CPU – Such processors can perform many operations
simultaneously
• Central Processing Unit (CPU)—This “administrative” section
coordinates and supervises the operation of the other sections – A dual-core processor has two CPUs, a quad-core
– Tells the input unit when to read information into the memory unit processor has four and an octa-core processor has
– Tells the ALU when to use information from the memory unit in eight.
calculations – Intel has some processors with up to 72 cores.
– Tells the output unit when to send information from the memory
unit to specific output devices

Copyright © 2022 Pearson Education, Inc. All Rights Reserved Copyright © 2022 Pearson Education, Inc. All Rights Reserved

4
1.2.2 Computer Organization (5 of 5) 1.3 Data Hierarchy
• Secondary Storage Unit—This is the long-term, high-capacity • Data items processed by
“warehousing” section
computers form a data
– Programs and data not actively being used by the other units are
placed on secondary storage devices until they’re again needed, hierarchy that becomes
possibly hours, days, months or even years later larger and more complex
– Information on secondary storage devices is persistent in structure as we
– Secondary storage information takes much longer to access than progress from the
information in primary memory, but its cost per byte is much less
simplest data items
– Examples of secondary storage devices include solid-state drives
(SSDs), USB flash drives, hard drives and read/write Blu-ray drives
(called “bits”) to richer
– Many current drives hold terabytes (TB) of data
ones, such as characters
– A terabyte is approximately one trillion bytes and fields

Copyright © 2022 Pearson Education, Inc. All Rights Reserved Copyright © 2022 Pearson Education, Inc. All Rights Reserved

1.3 Data Hierarchy—Bits 1.3 Data Hierarchy—Characters


• A bit is short for “binary digit”—a digit that can assume 0 • Work with data in the low-level form of bits is tedious
or 1 • Instead, people prefer to work with decimal digits (0–9), letters (A–Z
and a–z) and special symbols such as
• Bits form the basis of the binary number system, which
we discuss in our “Number Systems” appendix – $@% & *  – ": ;, ?/
• Digits, letters and special symbols are known as characters
• The computer’s character set contains the characters used to write
programs and represent data items
• C uses the ASCII (American Standard Code for Information
Interchange) character set by default
• C also supports Unicode® characters composed of one, two, three or
four bytes (8, 16, 24 or 32 bits, respectively).

Copyright © 2022 Pearson Education, Inc. All Rights Reserved Copyright © 2022 Pearson Education, Inc. All Rights Reserved

5
1.3 Data Hierarchy—Fields 1.3 Data Hierarchy—Records
• Just as characters are composed of bits, fields are • Several related fields can be used to compose a record
composed of characters or bytes • An employee record might consist of
• A field is a group of characters or bytes that conveys – Employee identification number (a whole number).
meaning – Name (a group of characters).
• A field consisting of uppercase and lowercase letters – Address (a group of characters).
could represent a person’s name – Hourly pay rate (a number with a decimal point).
– Year-to-date earnings (a number with a decimal point).
• A field consisting of decimal digits could represent a
– Amount of taxes withheld (a number with a decimal point).
person’s age in years
• A record is a group of related fields

Copyright © 2022 Pearson Education, Inc. All Rights Reserved Copyright © 2022 Pearson Education, Inc. All Rights Reserved

1.3 Data Hierarchy—Files 1.3 Data Hierarchy—Databases


• A file is a group of related records • A database is a collection of data organized for easy
access and manipulation
• A file contains arbitrary data in arbitrary formats
• The most popular model is the relational database, in
• Some operating systems view a file simply as a
which data is stored in simple tables
sequence of bytes—any organization of the bytes in a
file, such as organizing the data into records, is a view • A table includes records and fields
created by the application programmer
• A table of students might include
• It’s not unusual for an organization to have many files, – first name, last name, major, year, student ID number
some containing billions, or even trillions, of characters of and grade-point-average
information
• The data for each student is a record, and the individual
pieces of information in each record are the fields
Copyright © 2022 Pearson Education, Inc. All Rights Reserved Copyright © 2022 Pearson Education, Inc. All Rights Reserved

6
1.3 Data Hierarchy—Big Data (1 of 2) 1.3 Data Hierarchy—Big Data (2 of 2)
• The amount of data being produced worldwide is
enormous, and its growth is accelerating Unit Bytes Which is approximately
1 kilobyte (KB) 1024 bytes 103 bytes (1024 bytes exactly)
• Big data applications deal with massive amounts of data
10 c ubed

1 megabyte (MB) 1024 kilobytes 10 6 (1,000,000) bytes


1 0 to th e si x th po we r

• This field is growing quickly, creating lots of opportunities 1 gigabyte (GB) 1024 megabytes 109 (1,000,000,000) bytes
1 0 to th e ni n th po we r

for software developers 1 terabyte (TB) 1024 gigabytes 1012 (1,000,000,000,000) bytes
1 0 to th e twe l fth p owe r

1 petabyte (PB) 1024 terabytes 1015 (1,000,000,000,000,000) bytes


• Millions of information technology (IT) jobs globally
1 0 to th e fi ftee nth po we r

1 exabyte (EB) 1024 petabytes 1018 (1,000,000,000,000,000,000) bytes


already support big-data applications.
1 0 to th e ei g htee n th po we r

1 zettabyte (ZB) 1024 exabytes 1021 (1,000,000,000,000,000,000,000) bytes


1 0 to th e Twe nty fi rs t p owe r

Copyright © 2022 Pearson Education, Inc. All Rights Reserved Copyright © 2022 Pearson Education, Inc. All Rights Reserved

1.3 Data Hierarchy—Twitter®: A Favorite 1.4 Machine Languages, Assembly


Big-Data Source Languages and High-Level Languages
• One big-data source favored by developers is Twitter • Programmers write instructions in various programming
• There are approximately 800,000,000 tweets per day languages, some directly understandable by computers
and others requiring intermediate translation steps
• Though tweets appear to be limited to 280 characters, Twitter
actually provides almost 10,000 bytes of data per tweet to • Hundreds of such languages are in use today
programmers who want to analyze tweets.
• These may be divided into three general types:
• So 800,000,000 times 10,000 is about 8,000,000,000,000 – Machine languages.
bytes or 8 terabytes (TB) of data per day. That’s big data.
– Assembly languages.
• Data mining is the process of searching through extensive – High-level languages.
collections of data, often big data, to find insights that can be
valuable to individuals and organizations

Copyright © 2022 Pearson Education, Inc. All Rights Reserved Copyright © 2022 Pearson Education, Inc. All Rights Reserved

7
1.4 Machine Languages, Assembly Languages and
1.4 Machine Languages, Assembly Languages and High-Level Languages—Assembly Languages and
High-Level Languages—Machine Languages Assemblers

• Any computer can directly understand only its own • Programming in machine language was simply too slow
machine language, defined by its hardware design and tedious for most programmers
• Machine languages generally consist of strings of • Instead of using the strings of numbers that computers
numbers (ultimately reduced to 1s and 0s) that instruct could directly understand, programmers began using
computers to perform their most elementary operations English-like abbreviations to represent elementary
one at a time operations
• Machine languages are machine-dependent—a particular • These abbreviations formed the basis of assembly
machine language can be used on only one type of languages
computer
• Translator programs called assemblers were developed
• Such languages are cumbersome for humans to convert assembly-language programs to machine
language at computer speeds
Copyright © 2022 Pearson Education, Inc. All Rights Reserved Copyright © 2022 Pearson Education, Inc. All Rights Reserved

1.4 Machine Languages, Assembly Languages and


High-Level Languages—High-Level Languages and 1.4 Machine Languages, Assembly Languages
Compilers and High-Level Languages—Interpreters

• To speed the programming process, high-level languages were • Compiling a large high-level language program into
developed in which single statements could accomplish substantial machine language can take considerable computer time
tasks
• A typical high-level-language program contains many statements,
• Interpreters execute high-level language programs
known as the program’s source code directly
• Translator programs called compilers convert high-level-language • Interpreters avoid compilation delays, but your code runs
source code into machine language slower than compiled programs
• High-level languages allow you to write instructions that look almost • Some programming languages, such as Java and
like everyday English and contain common mathematical notations
Python, use a clever mixture of compilation and
• C is among the world’s most widely used high-level programming interpretation to run programs
languages.

Copyright © 2022 Pearson Education, Inc. All Rights Reserved Copyright © 2022 Pearson Education, Inc. All Rights Reserved

8
1.5 Operating Systems 1.6 The C Programming Language
• Operating systems are software that make using computers more • The C Programming Language
convenient for users, software developers and system administrators – C evolved from two earlier languages, BCPL and B
▪ BCPL was developed in 1967 by Martin Richards as a language for
• Provide services that allow applications to execute safely, efficiently
writing operating systems and compilers
and concurrently with one another.
▪ Ken Thompson modeled many features in his B language after
• The software that contains the core operating-system components is their counterparts in BCPL, and in 1970 he used B to create early
called the kernel versions of the UNIX operating system at Bell Laboratories.
– The C language was evolved from B by Dennis Ritchie at Bell
• Linux, Windows and macOS are popular desktop computer operating Laboratories and was originally implemented in 1972
systems – C initially became widely known as the development language of UNIX
– Each is partially written in C – Many of today’s leading operating systems are written in C and/or C++
• The most popular mobile operating systems used in smartphones – C is mostly hardware-independent—with careful design, it’s possible to
and tablets are Google’s Android and Apple’s iOS write C programs that are portable to most computers.

Copyright © 2022 Pearson Education, Inc. All Rights Reserved Copyright © 2022 Pearson Education, Inc. All Rights Reserved

1.6 The C Programming Language—Built 1.6 The C Programming Language—


for Performance Standardization

• C is widely used to develop systems that demand • C’s rapid expansion to various hardware platforms (that is, types of
performance computer hardware) led to many similar but often incompatible C
versions
– operating systems
• This was a serious problem for programmers who needed to develop
– embedded systems code for several platforms
– real-time systems
• In 1983, the American National Standards Committee on Computers
– communications systems: and Information Processing (X3) created the X3J11 technical
committee to “provide an unambiguous and machine-independent
• By the late 1970s, C had evolved into what’s now definition of the language.”
referred to as “traditional C.”
• In 1989, the standard was approved in the United States through the
American National Standards Institute (ANSI), then worldwide
through the International Standards Organization (ISO)

Copyright © 2022 Pearson Education, Inc. All Rights Reserved Copyright © 2022 Pearson Education, Inc. All Rights Reserved

9
1.6 The C Programming Language—The 1.7 The C Standard Library and Open-
C11 and C18 Standards Source Libraries (1 of 2)

• We discuss the latest C standard (referred to as C11), • C programs consist of pieces called functions
which was approved in 2011 and updated with bug fixes • You can program all the functions you need to form a C
in 2018 (referred to as C18) program
• C11 refined and expanded C’s capabilities • However, most C programmers take advantage of the rich
collection of existing functions in the C standard library
• According to the C standard committee, the next C
standard is likely to be released in 2022 • Two parts to learning C programming:
• Because C is a hardware-independent, widely available – learning the C language itself, and
language, C applications often can run with little or no – learning how to use the functions in the C standard
modification on a wide range of computer systems library.
• Throughout the book, we discuss many of these functions

Copyright © 2022 Pearson Education, Inc. All Rights Reserved Copyright © 2022 Pearson Education, Inc. All Rights Reserved

1.7 The C Standard Library and Open- 1.7 The C Standard Library and Open-
Source Libraries (2 of 2) Source Libraries—Open-Source Libraries

• When programming in C, you’ll typically use the • There are enormous numbers of third-party and open-
following building blocks: source C libraries that can help you perform significant
– C standard library functions, tasks with modest amounts of code. GitHub lists over
– open-source C library functions, 32,000 repositories in their C category:
– functions you create yourself, and – https://github.com/topics/c
– functions other people have created and made • In addition, pages such as Awesome C provide curated
available to you. lists of popular C libraries for a wide range of application
areas.
• Throughout the book, we focus on using the existing C
– https://github.com/kozross/awesome-c
standard library to leverage your program-development
efforts and avoid “reinventing the wheel.”
• This is called software reuse.
Copyright © 2022 Pearson Education, Inc. All Rights Reserved Copyright © 2022 Pearson Education, Inc. All Rights Reserved

10
1.8 Other Popular Programming 1.8 Other Popular Programming
Languages (1 of 3) Languages (2 of 3)
• BASIC was developed in the 1960s at Dartmouth College to familiarize • Java—Sun Microsystems in 1991 funded an internal corporate
novices with programming techniques research project led by James Gosling, which resulted in the
– Many of its latest versions are object-oriented C++-based object-oriented programming language called Java
• C++, which is based on C, was developed by Bjarne Stroustrup in the early – “write once, run anywhere”
1980s at Bell Laboratories
– used in enterprise applications, web servers, applications
– C++ provides features that enhance the C language and adds object-
oriented programming capabilities for consumer devices, …

• Python is an object-oriented language that was released publicly in 1991 • C# (based on C++ and Java) is one of Microsoft’s three
– Developed by Guido van Rossum of the National Research Institute for primary object-oriented programming languages
Mathematics and Computer Science in Amsterdam – developed to integrate the web into computer applications
– Python has rapidly become one of the world’s most popular
– now widely used to develop many kinds of applications
programming languages, especially for educational and scientific
computing, and in 2017 it surpassed the programming language R as – As part of Microsoft’s many open-source initiatives, they
the most popular data-science programming language now offer open-source versions of C# and Visual Basic
Copyright © 2022 Pearson Education, Inc. All Rights Reserved Copyright © 2022 Pearson Education, Inc. All Rights Reserved

1.8 Other Popular Programming 1.9 Typical C Program-Development


Languages (3 of 3) Environment
• JavaScript is a widely used scripting language • C systems generally consist of several parts
– primarily used to add programmability to web pages – a program-development environment
– All major web browsers support it.
– the language
– Many Python visualization libraries output JavaScript for use in web
pages – the C standard library
– Tools such as NodeJS also enable JavaScript to run outside of web
• C programs typically go through six phases to be executed
browsers
– Edit
• Swift is Apple’s programming language for iOS/macOS apps
– Includes features from Objective-C, Java, C#, Ruby, Python and
– Preprocess
more – Compile
– open-source, so it can be used on non-Apple platforms as well. – Link
• R is a popular open-source programming language for statistical – Load
applications and visualization
– Execute
Copyright © 2022 Pearson Education, Inc. All Rights Reserved Copyright © 2022 Pearson Education, Inc. All Rights Reserved

11
1.9.2 Phases 2 and 3: Preprocessing and
1.9.1 Phase 1: Creating a Program Compiling a C Program (1 of 3)

• Consists of editing a file in an editor program: • You give the command to compile the program
• Compiler translates it into machine-language code
• The compilation command invokes a preprocessor first
– Performs text manipulations on a program’s source-
code files
– Inserting the contents of other files
– Text replacements

Copyright © 2022 Pearson Education, Inc. All Rights Reserved Copyright © 2022 Pearson Education, Inc. All Rights Reserved

1.9.2 Phases 2 and 3: Preprocessing and 1.9.2 Phases 2 and 3: Preprocessing and
Compiling a C Program (2 of 3) Compiling a C Program (3 of 3)

• A syntax error occurs when the compiler cannot


recognize a statement because it violates the language
rules
– The compiler issues an error message to help you
locate and fix the incorrect statement.
• The C standard does not specify the wording for error
• Syntax errors are also called compile errors or compile-
time errors.

Copyright © 2022 Pearson Education, Inc. All Rights Reserved Copyright © 2022 Pearson Education, Inc. All Rights Reserved

12
1.9.3 Phase 4: Linking 1.9.4 Phase 5: Loading (1 of 2)

• C programs use functions defined elsewhere • Before a program can execute, the operating system
– standard libraries, open-source libraries or private libraries must load it into memory
of a particular project.
• Loader transfers the executable image from disk to
• The object code produced by the C compiler typically contains memory
“holes”
• Additional components from shared libraries that support
• Linker links a program’s object code with the code for the the program also are loaded
missing functions to produce an executable image (with no
missing pieces)

Copyright © 2022 Pearson Education, Inc. All Rights Reserved Copyright © 2022 Pearson Education, Inc. All Rights Reserved

1.9.4 Phase 5: Loading (2 of 2) 1.9.5 Phase 6: Execution


• Finally, the computer, under the control of its CPU,
executes the program one instruction at a time

Copyright © 2022 Pearson Education, Inc. All Rights Reserved Copyright © 2022 Pearson Education, Inc. All Rights Reserved

13
1.9.6 Problems That May Occur at 1.9.7 Standard Input, Standard Output
Execution Time and Standard Error Streams

• Errors that occur as programs run are called runtime • Most C programs input and/or output data
errors or execution-time errors
• Certain C functions take their input from stdin (the
• Fatal errors cause a program to terminate immediately standard input stream), which is normally the keyboard
without successfully performing its job
• Data is often output to stdout (the standard output
• Nonfatal errors allow programs to run to completion, stream), which is normally the computer screen
often producing incorrect results
• Data also may be output to devices such as disks and
printers
• There’s also a standard error stream referred to as stderr,
which is normally connected to the screen and used to
display error messages
Copyright © 2022 Pearson Education, Inc. All Rights Reserved Copyright © 2022 Pearson Education, Inc. All Rights Reserved

Copyright

This work is protected by United States copyright laws and is


provided solely for the use of instructors in teaching their
courses and assessing student learning. Dissemination or sale of
any part of this work (including on the World Wide Web) will
destroy the integrity of the work and is not permitted. The work
and materials from it should never be made available to students
except by instructors using the accompanying text in their
classes. All recipients of this work are expected to abide by these
restrictions and to honor the intended pedagogical purposes and
the needs of other instructors who rely on these materials.

Copyright © 2022 Pearson Education, Inc. All Rights Reserved

14

You might also like