Part I: The Basics


Programming languages have distinctive features that determine the kinds of applications for which they are well suited. They also share many fundamental attributes. Essentially all languages provide:

  • Built-in data types such as integers, characters, and so forth

  • Expressions and statements to manipulate values of these types

  • Variables, which let us give names to the objects we use

  • Control structures, such as if or while, that allow us to conditionally execute or repeat a set of actions

  • Functions that let us abstract actions into callable units of computation

Most modern programming languages supplement this basic set of features in two ways: They let programmers extend the language by defining their own data types, and they provide a set of library routines that define useful functions and data types not otherwise built into the language.

In C++, as in most programming languages, the type of an object determines what operations can be performed on it. Depending on the type of the objects involved, a statement might or might not be legal. Some languages, notably Smalltalk and Python, check the types involved in expressions at run time. In contrast, C++ is a statically typed language; type-checking is done at compile time. As a consequence, the compiler must be told the type of every name used in the program before that name can be used.

C++ provides a set of built-in data types, operators to manipulate those types, and a small set of statements for program flow control. These elements form an alphabet with which many large, complex real-world systems can and have been written. At this basic level, C++ is a simple language. Its expressive power arises from its support for mechanisms that allow the programmer to define new data structures.

Perhaps the most important feature in C++ is the class, which allows programmers to define their own data types. In C++ such types are sometimes called "class types" to distinguish them from the types that are built into the language. Some languages let programmers define data types that specify only what data make up the type. Others, like C++, allow programmers to define types that include operations as well as data. One of the primary design goals of C++ is to let programmers define their own types that are as easy to use as the built-in types. The Standard C++ library uses these features to implement a rich library of class types and associated functions.

The first step in mastering C++learning the basics of the language and libraryis the topic of Part I. Chapter 2 covers the built-in data types and looks briefly at the mechanisms for defining our own new types. Chapter 3 introduces two of the most fundamental library types: string and vector. Arrays, which are covered in Chapter 4, are a lower-level data structure built into C++ and many other languages. Arrays are similar to vectors but harder to use. Chapters 5 through 7 cover expressions, statements, and functions. This part concludes in Chapter 8, which covers the most important facilities from the IO library.


CONTENTS
 

Chapter 2 Variables and Basic Types

 

Chapter 3 Library Types

 

Chapter 4 Arrays and Pointers

 

Chapter 5 Expressions

 

Chapter 6 Statements

 

Chapter 7 Functions

 

Chapter 8 The IO Library



C++ Primer
C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2006
Pages: 223
Authors: Stephen Prata

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net