How to define C ++ variables in C ++?

Source: Internet
Author: User

When using C ++ variable variables, C ++ variable names are usually defined as names that are easy to read and can describe the usefulness of the contained data, instead of using some obscure abbreviations such as A or B2, I hope to bring you the information you want after reading this article.

In fact, the C language is introduced here. Only C ++ is transferred to C ++ in Lesson 2nd "C ++ basics. Readers do not have to worry about which is from C and which is from C ++, because all these are in C ++. C ++ is difficult to introduce in sequence, because all the features we will introduce are cross-cutting.

I prepared an introduction and pieced it together. By the end of Lesson 3rd "Advanced C ++", you will have a complete understanding of the C ++ language. It doesn't matter if you don't have a certain concept. Some concepts must be fully understood after practice.

C ++ Variables

Let's start with the variable. Variable is actually the name assigned to the memory address. After the C ++ variable is declared, you can use it to operate data in the memory. The following are examples. Two variables are used in the following code segments. The statements at the end of each statement describe what happens when the statement is executed:

 
 
  1. int x;// variable declared as an integer variable   
  2.  
  3. x = 100;// 'x' now contains the value 100   
  4.  
  5. x +=50;// 'x' now contains the value 150   
  6.  
  7. int y = 150;// 'y' declared and initialized to 150   
  8.  
  9. x += y;// 'x' now contains the value 300   
  10.  
  11. x++;// 'x' now contains the value 301  


Variable is the computer memory address reserved for a specific value. Note that the value of x Changes During Variable operations. The C ++ operator of the Operation variable will be introduced later. Variables declared with warnings but not initialized contain random values. Because the memory to which the variable points has not been initialized, you do not know the value of the memory address.

In this example, the variable y is not initialized in advance, so x may obtain any value. The exception is that the global variable and the variable declared with static modification are always initialized to 0. All other variables include random values before initialization or assignment. Variable names can contain uppercase letters, lowercase letters, numbers, and underscores.

It cannot contain spaces or other special characters. The C ++ variable name must start with a letter or underline. Generally, it is not good to underline or Double underline the C ++ variable name. The maximum length allowed by the variable name varies with the compiler. It is absolutely safe if the variable name is kept below 32 characters.

In reality, any C ++ variable name with more than 20 characters is not practical. C ++ can take full advantage of Object-Oriented Programming (OOP. OOP is not just a new term, but has its practical significance. It can generate reusable objects. The new term object is the same as the component described above.

The software block component that completes a specific programming task is an object, but the object is not an entire component. This will be explained later ). Objects only show the required parts to the programmers who use the objects. This simplifies the use of objects. All internal mechanisms that users do not need to know are hidden behind the scenes. All of this is included in the concept of object-oriented programming. OOP can be programmed in a modular way to avoid starting from scratch each time.

The C ++ Builder program is oriented to OOP, because C ++ Builder uses a large number of components. After a component is generated, you can use it again in any C ++ Builder program. The components can also be expanded to generate new components with new functions through inheritance. The best thing is that the component hides all content details, allowing programmers to focus on making full use of the component.

  1. Differences between standard input implementation methods in C and C ++
  2. How does the C ++ compiler allocate storage space for Const constants?
  3. Basic Conception and method of C ++ Class Library Design
  4. Several Methods for converting C ++ Language
  5. How to better compile C ++ code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.