C + + is a powerful language that can be used to do work in other languages. However, there is a cost to this powerful feature. When you start using C + +, you may experience problems with memory overflows and access failures, causing the program to panic. Here is a brief overview of the C + + language base. C + + language itself has monographs introduced, this kind of book is also particularly thick, so don't expect me to use words to say clearly. After the reader finishes the book and uses C + + Builder general time, finally the C + + language for a more in-depth understanding.
C + + can make the most of the advantage of object-oriented programming (OOP). OOP is not just a term, but has its practical meaning and can generate reusable objects. The new term object, like the artifacts described earlier, is a piece of software that completes a particular programming task (the widget is an object, but the object is not all artifacts, which will be explained later). Objects simplify the use of objects by displaying only the necessary parts to the user (the programmer who uses the object). All the internal mechanisms that users don't need to know are hidden behind the scenes. All of this is included in the concept of object-oriented programming. OOP can be programmed with a modular approach to avoid starting from scratch each time. C + + Builder programs are object-oriented, because C + + Builder use artifacts heavily. After building artifacts (you build or C + + Builder built-in artifacts), you can reuse them in any C + + Builder program. Artifacts can also be extended to generate new artifacts with new functionality through inheritance. The best part is that the widget hides all the details of the content, enabling programmers to focus on making the most of the artifacts.
Introduction to Getting Started
C + + is based on the C language, which is called the "C language with Class" before C + +. This C-language foundation is still important in today's C + + programs. C + + is not a substitute for C, but rather a complement and support. The remainder of this chapter and the next chapters introduce the C-language section in C + +. In fact, this is the C language, the 2nd lesson "C + + base" in the C + +. Readers don't have to worry about which one comes from C, which is C + + because it's all in C + +. The C + + language is difficult to introduce in order because all of the features we want to introduce are interleaved. I'm going to introduce one piece at a time and then piece it together. By the end of the 3rd lesson, "Advanced C + +", you will have a complete understanding of the C + + language. It doesn't matter if you don't master a concept at once, and some concepts have to be fully understood through practice.
Variable
Let's talk about the variables. The variable (variable) is actually the name that gives the memory address. After you declare a variable, you can use it to manipulate the data in memory. Here are a few examples to illustrate. The following code segment uses two variables, with a description statement at the end of each statement describing what happens when the statement is executed:
int x;//variable declared as an integer variable
x = 100;//' x ' now contains the value 100
x +=50;//' x ' now contains the value 150
int y = 150;//' y ' declared and initialized to 150
x = y;//' x ' now contains the value 300
x++;//' x ' now contains the value 301
The new term variable (variable) is the memory address of the computer that is left as a value. Note that the value of x changes when the variable is manipulated and later describes the C + + operator of the operation variable. A variable with a warning declaration and not initialized contains a random value. The memory address does not know what value it contains because the memory that the variable points to is not initialized.
For example, the following code
int k;
int y;
x=y+10; oops!
In this case, the variable y is not initialized beforehand, so x can get any value. The exception is that global variables and variables declared with the static modifier are always initialized to 0. All other variables contain a random value before initializing or assigning a value. Variable names can be mixed with uppercase, lowercase letters, and numbers and underscores (_), but cannot contain spaces and other special characters. Variable names must begin with a letter or underscore. In general, the variable name below the underline or double underline start bad. The maximum allowable length of a variable name varies from one compiler to another. If the variable name remains below 32 characters, it is absolutely safe. In practice, any variable names that are more than 20 characters are not practical.
The following example is an example of a valid variable name:
int averylongvariablename;//a Long variable name
int my_variable;//A variable with a underscore
Int_ x;//ok,but not advisedint x;//uppercase name
int labe12;//A variable name containing a number
int Getitemsincontainer (); Hi pete!
Explains that the variable names in C + + are case-sensitive, and the following variables are different: int xpos;int xpos; If your original language does not consider the case (such as Pascal), then the language that starts to touch the case may not be appropriate.