Skip to main content Accessibility help
×
Hostname: page-component-848d4c4894-4rdrl Total loading time: 0 Render date: 2024-07-04T17:18:15.868Z Has data issue: false hasContentIssue false

Chapter 5 - Fundamental concepts

Published online by Cambridge University Press:  05 June 2012

David Yevick
Affiliation:
University of Waterloo, Ontario
Get access

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 Engineering
C++, Java and Octave Numerical Programming with Free Software Tools
, pp. 26 - 34
Publisher: Cambridge University Press
Print publication year: 2012

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

  • Fundamental concepts
  • David Yevick, University of Waterloo, Ontario
  • Book: A Short Course in Computational Science and Engineering
  • Online publication: 05 June 2012
  • Chapter DOI: https://doi.org/10.1017/CBO9781139022262.005
Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

  • Fundamental concepts
  • David Yevick, University of Waterloo, Ontario
  • Book: A Short Course in Computational Science and Engineering
  • Online publication: 05 June 2012
  • Chapter DOI: https://doi.org/10.1017/CBO9781139022262.005
Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

  • Fundamental concepts
  • David Yevick, University of Waterloo, Ontario
  • Book: A Short Course in Computational Science and Engineering
  • Online publication: 05 June 2012
  • Chapter DOI: https://doi.org/10.1017/CBO9781139022262.005
Available formats
×