|
|
|
|
|
|
|
turn a value when main finishes executing. By convention, a return value of 0 means everything went OK. A return value of anything else (typically 1,2, ) means something went wrong. Later in this book we look at situations in which you might want to return a value other than 0 from main. For the time being, we'll always conclude the execution of main by returning the value 0. |
|
|
|
|
|
|
|
|
We have looked only briefly at the overall picture of what a C++ program looks likea collection of one or more functions, including main. And we have mentioned what is special about the main functionit is a required function, execution begins there, and it returns a value to the operating system. Now it's time to begin looking at the details of the C++ language. |
|
|
|
|
|
|
|
|
A programming language is a set of rules, symbols, and special words used to construct a program. There are rules for both syntax (grammar) and semantics (meaning). |
|
|
|
 |
|
 |
|
|
Syntax The formal rules governing how valid instructions are written in a programming language. |
|
|
|
 |
|
 |
|
|
Semantics The set of rules that determines the meaning of instructions written in a programming language. |
|
|
|
|
|
|
|
|
Syntax is a formal set of rules that defines exactly what combinations of letters, numbers, and symbols can be used in a programming language. There is no room for ambiguity in the syntax of a programming language because the computer can't think; it doesn't know what we mean. To avoid ambiguity, syntax rules themselves must be written in a very simple, precise, formal language called a metalanguage. |
|
|
|
 |
|
 |
|
|
Metalanguage A language that is used to write the syntax rules for another language. |
|
|
|
|
|
|
|
|
Learning to read a metalanguage is like learning to read the notations used in the rules of a sport. Once you understand the notations, you can read the rule book. It's true that many people learn a sport simply by watching others play, but what they learn is usually just enough to allow them to take part in casual games. You could learn C++ by following the examples in this book, but a serious programmer, like a serious athlete, must take the time to read and understand the rules. |
|
|
|
|
|