The Elements of a C++ Program
- Begin reading chapter 2.
- This may or may not make sense but read it anyway.
- Pay attention to terms.
- Part of the class is to learn the vocabulary.
- In programming syntax is the set of formal rules governing how valid instructions are written in a programming language.
- You have experience with English syntax.
- Noun/verb agreement.
- Spelling.
- Punctuation.
- C++ (or any programming language) has a syntax as well.
- A compiler is a program that translates a program from
a high level language (like C++) to machine code.
- In this process, the compiler checks for syntax errors
- A syntax error is a message from the compiler that tells you where you have made a error in the language syntax.
- We are generally given a line number and an attempt to identify the error.
- You should fix syntax errors from the first (lowest line number) first.
- Semantics are the set of rules that determines the meaning of the instructions written in a programming language.
- We can make sentences in English which are syntactically correct but are utter nonsense.
- Or sentences which are ambiguous.
- But it takes someone who understands meaning of the language to determine this.
- The same is true with programming.
- We only find semantic errors when we run our programs.
- Or trace them by hand.
- You will spend quite a bit of time learning syntax at the beginning of your programming carrier.
- Syntax errors will dominate your programming time when you start.
- Later you will address semantic errors.
- A Reserved Word is a word that has special meaning in C++
- We can not change the reserved words.
- They are listed on page 985.
- These are the words that make up the language
- An Identifier is a user defined name associated with a function or data object.
- We will use identifiers as we write program.
- An identifier must (These are syntax rules)
- Start with a letter (A-Z,a-Z) or the underscore _
- Must contain only letters, the underscore and digits (0-9)
- Must not be a reserved word.
- As we program, we learn programming conventions
- These are sometimes referred to as a style guide.
- These are self imposed rules which make it easier to understand our programs.
- Or perhaps imposed by employers, coordinators, teachers, ...
- Google has a set.
- As do many projects and companies (Just Google it)
- As we learn different elements of C++, we will learn the associated conventions I would like you to employ.
- An operatoris a C++ symbol which performs an operation.
- This includes math things (+,*,-,/)
- Comparison things (<, >)
- Logical things (and, or, not)
- Other things too.
- We will spend time learning what operators do.
- A list of operators is on page 986.
- A data type is a specific set of data values, along with a set of operations on those values.
- We will study:
- Integer
- Character
- Float
- Boolean
- String
- Stream
- We need to know the data type so the compiler (computer really) can tell what we have stored in memory
- Everything is really just stored as a collection of bits.
- Based on the type of the data stored there, it is treated as one of the above data types.
- Programs manipulate data. To do so, we must declare a place to store that data.
- A declaration is a statement which associates an identifier with a data object, function or data type so that the programmer can refer to the item by name.
- This frequently associates a name and a data type with a location in memory.