Published online by Cambridge University Press: 05 June 2012
Before discussing the C++ language in detail, we summarize its conceptualfoundations. Since C++ consistently adheres to a small number of basicprinciples, acquiring a working understanding of these greatly hastens learningof C++ syntax.
Overview of program structure
The smallest unit of a C++ program is a token, which is a letteror symbol that the compiler can process. Appropriate groups of tokens yieldwords. Of these, identifiers (variable names) formatomic (single-element) expressions.Operators combine expressions to form new expressions.Terminating a valid expression with a semicolon yields astatement, which is equivalent to a sentence. Ablock, which is analogous to a paragraph, unifies andisolates one or more statements from the remainder of the program.Control structures determine the program flow according tothe outcome of logical operations, while functions and possiblysubroutines modularize compound statements by associating alabel with a frequently occurring sequence of statements. Finally,classes and objects structure relatedvariables and functions into generalized arrays. These, like a chapter, describea 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 textwithin a line from left to right. A program is read as a sequence of tokensseparated by non-printing whitespace characters, which includetabs, carriage returns and spaces. Valid tokens are a–z, A–Z, 0–9 and certainpunctuation characters. Upper- and lower-case letters represent different tokenssuch that myVariable and myvariable are unrelated names. A word is a sequence oftokens terminated by whitespace. A reserved keyword is a wordsuch as int or if for which the complier has a specialinterpretation.
To save this book to your Kindle, first ensure no-reply@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.
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.
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.