Many people say that C++primer is not suitable for getting started, this series of introductory articles proves: This is a lie.
Introduction to Chapter I.
This chapter describes most of the basic features of C + +: Built-in types, library types, class types, variables, expressions, statements, and functions.
1.1. Writing a simple C + + program
Each C + + program contains one or more functions, and must have a name of main. A function consists of a sequence of statements that perform function functions. The operating system executes the program by calling the main function, and the main function executes the statement that makes up its own and returns a value to the operating system.
The following is a simple main function, which does not perform any function, just returns a value:
int main () {
return 0;
}
The operating system uses the value returned by the main function to determine whether the program completed successfully. Returning a value of 0 indicates that the program completed successfully.
main functions are special in many ways, it is important that each C + + program must contain the main function, and that the main function is (the only) function that is explicitly called by the operating system.
The latter part of the function body function definition is a block of statements starting with curly braces and ending in curly braces:
{return 0; }
1.1.1. Compiling and executing programs
To facilitate learning for beginners, I made a Linux virtual machine, I installed a variety of tools in it, easy to learn and expand. Placed on the cloud disk of the alliance, you can download this virtual machine, follow-up I will make a series of learning videos, for not willing to read the same through watching video play C + +.
But, again, it is an essential step in learning.
compile:
$ cc prog1.cc
Here CC is the compiler command name, $ represents the system prompt. The compiler outputs an executable file that we can invoke by name. In our system, the compiler produces an executable file named A.exe. The UNIX compiler places the executable file in a file named A.out. To run the executable file, you can give the file name at the command prompt:
$ a.exe
There's nothing! Yes, this program only returns 0, telling the operating system that the program ends normally, and nothing else is done. This is already a normal C + + program. Congratulations Hi, you have finished it.
Open link
Focus on the public platform: the Programmer Interaction Alliance (coder_online), you can get the first original technical articles, and (Java/c/c++/android/windows/linux) technology Daniel Friends, online communication programming experience, get programming basics, Solve programming problems. Programmer Interactive Alliance, Developer's own home.
C + + Primer Quick Learning First Chapter Introduction