08.01.2023 Views

Learn to Program with C_ Learn to Program using the Popular C Programming Language ( PDFDrive )

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 1 ■ Elementary Programming Concepts

You can think of memory as a series of storage locations, numbered consecutively starting at 0.

Thus you can speak of memory location 27 or memory location 31548. The number associated

with a memory location is called its address.

A computer runs a program by executing its first instruction, then the second, then the third,

and so on. It is possible that one instruction might say to jump over several instructions to a

particular one and continue executing from there. Another might say to go back to a previous

instruction and execute it again.

No matter what the instructions are, the computer faithfully executes them exactly as

specified. That is why it is so important that programs specify precisely and exactly what must be

done. The computer cannot know what you intend, it can only execute what you actually write.

If you give the computer the wrong instruction, it will blindly execute it just as you specify.

1.4 Data Types

Every day we meet names and numbers—at home, at work, at school, or at play. A person’s name is

a type of data; so is a number. We can thus speak of the two data types called “name” and “number.”

Consider the statement:

Caroline bought 3 dresses for $199.95

10

Here, we can find:

• An example of a name: Caroline.

• Two examples of numbers: 3 and 199.95.

Usually, we find it convenient to divide numbers into two kinds:

1. Whole numbers, or integers.

2. Numbers with a decimal point, so-called real or floating-point numbers.

In the example, 3 is an integer and 199.95 is a real number.

Exercise: Identify the data types—names, integers,

and real numbers—in the following

1. Bill’s batting average was 35.25 with a highest score of 99.

2. Abigail, who lives at 41 Third Avenue, worked 36 hours at $11.50 per hour.

3. In his 8 subjects, Richard’s average mark was 68.5.

Generally speaking, programs are written to manipulate data of various types. We use the term numeric

to refer to numbers (integer or floating-point). We use the term string to refer to non-numeric data such

as a name, address, job description, title of a song, or vehicle number (which is not really a number as

far as the computer is concerned—it usually contains letters, e.g., PAB6052).

Programming languages in general, and C in particular, precisely define the various types of data that

can be manipulated by programs written in those languages. Integer, real (or floating-point), character

(data consisting of a single character such as 'K' or '%'), and string data types are the most common.

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!