Book contents
- Frontmatter
- Contents
- Chapter 1 Introduction
- Chapter 2 Octave programming
- Chapter 3 Installing and running the Dev-C++ programming environment
- Chapter 4 Introduction to computer and software architecture
- Chapter 5 Fundamental concepts
- Chapter 6 Procedural programming basics
- Chapter 7 An introduction to object-oriented analysis
- Chapter 8 C++ object-oriented programming syntax
- Chapter 9 Arrays and matrices
- Chapter 10 Input and output streams
- Chapter 11 References
- Chapter 12 Pointers and dynamic memory allocation
- Chapter 13 Memory management
- Chapter 14 The static keyword, multiple and virtual inheritance, templates and the STL
- Chapter 15 Creating a Java development environment
- Chapter 16 Basic Java programming constructs
- Chapter 17 Java classes and objects
- Chapter 18 Advanced Java features
- Chapter 19 Introductory numerical analysis
- Chapter 20 Linear algebra
- Chapter 21 Fourier transforms
- Chapter 22 Differential equations
- Chapter 23 Monte Carlo methods
- Chapter 24 Partial differential equations
- Index
Chapter 5 - Fundamental concepts
Published online by Cambridge University Press: 05 June 2012
- Frontmatter
- Contents
- Chapter 1 Introduction
- Chapter 2 Octave programming
- Chapter 3 Installing and running the Dev-C++ programming environment
- Chapter 4 Introduction to computer and software architecture
- Chapter 5 Fundamental concepts
- Chapter 6 Procedural programming basics
- Chapter 7 An introduction to object-oriented analysis
- Chapter 8 C++ object-oriented programming syntax
- Chapter 9 Arrays and matrices
- Chapter 10 Input and output streams
- Chapter 11 References
- Chapter 12 Pointers and dynamic memory allocation
- Chapter 13 Memory management
- Chapter 14 The static keyword, multiple and virtual inheritance, templates and the STL
- Chapter 15 Creating a Java development environment
- Chapter 16 Basic Java programming constructs
- Chapter 17 Java classes and objects
- Chapter 18 Advanced Java features
- Chapter 19 Introductory numerical analysis
- Chapter 20 Linear algebra
- Chapter 21 Fourier transforms
- Chapter 22 Differential equations
- Chapter 23 Monte Carlo methods
- Chapter 24 Partial differential equations
- Index
Summary
Before discussing the C++ language in detail, we summarize its conceptual foundations. Since C++ consistently adheres to a small number of basic principles, acquiring a working understanding of these greatly hastens learning of C++ syntax.
Overview of program structure
The smallest unit of a C++ program is a token, which is a letter or symbol that the compiler can process. Appropriate groups of tokens yield words. Of these, identifiers (variable names) form atomic (single-element) expressions. Operators combine expressions to form new expressions. Terminating a valid expression with a semicolon yields a statement, which is equivalent to a sentence. A block, which is analogous to a paragraph, unifies and isolates one or more statements from the remainder of the program. Control structures determine the program flow according to the outcome of logical operations, while functions and possibly subroutines modularize compound statements by associating a label with a frequently occurring sequence of statements. Finally, classes and objects structure related variables and functions into generalized arrays. These, like a chapter, describe a single topic, namely the properties of a related group of objects.
Tokens, names and keywords
The C++ compiler processes source-code lines in order of appearance and text within a line from left to right. A program is read as a sequence of tokens separated by non-printing whitespace characters, which include tabs, carriage returns and spaces. Valid tokens are a–z, A–Z, 0–9 and certain punctuation characters. Upper- and lower-case letters represent different tokens such that myVariable and myvariable are unrelated names. A word is a sequence of tokens terminated by whitespace. A reserved keyword is a word such as int or if for which the complier has a special interpretation.
- Type
- Chapter
- Information
- A Short Course in Computational Science and EngineeringC++, Java and Octave Numerical Programming with Free Software Tools, pp. 26 - 34Publisher: Cambridge University PressPrint publication year: 2012