Chapter 01 Introduction of Programming
3. Introduction of C++
A C++ program must have a function named
main
defined in only one source document.
3.1 Lexer in C++
-
symbol set
- letters
- numbers
- special characters
-
word
-
Identifier is composed of letters, numbers and underline. A legal identifier can’t start with a number and can’t be keyword.
- Capital letter and lowercase letter is different.
- There will be some common practice in defining a user-defined identifier. Following them will make your code more easier to be understood by others.
-
Keyword is predefined by the language itself and conveys some special and fixed meanings, which also has its own pattern of usage.
-
Literal is composed of numbers, characters and strings.
-
Operator describes the operation on data, which is also called operands.
-
Punctuation plays a role in syntax and semantics.
When editing a C++ code, the words above sometimes need to be separated using white-space character.
Comment is also a kind of white-space character, which does some illustration and demonstration to help the reader or other coder under stand the content.
There are two ways of writing comments:
//till the end of this line. /* between thiese two special forms, and can include multiple lines*/
\
is called continuation character, which allows you two write your code on the next line when the current line is not long enough. -
3.2 Procedure for the Running of a C++ Program
-
editing
- Use an editor to edit source code and store them in a document with a filename extension of
.h
or.cpp
.
- Use an editor to edit source code and store them in a document with a filename extension of
-
compiling
- Use a compiler(including a preprocessor, which will execute some part of the source code which is not actually a part of the C++ program) to translate the source code into the object code and store them in a document with a filename extension of
.obj
.
- Use a compiler(including a preprocessor, which will execute some part of the source code which is not actually a part of the C++ program) to translate the source code into the object code and store them in a document with a filename extension of
-
linking
- Use a linker to link all the files that make up the whole program and output an executive code stored in an executive document with a filename extension of
.exe
.
- Use a linker to link all the files that make up the whole program and output an executive code stored in an executive document with a filename extension of
-
executing/running