How to use C ++ variables of C ++?

Source: Internet
Author: User

A variable is a temporary place for storing data in a program. Only one variable or multiple variables can be used in the Code. The variables can store words, values, dates, and attributes. However, over the years, has the status of the C ++ community improved?

But first, we should see that the current programs are all included in the class, that is to say, all the Defined variables have become private members of the class, if you want to use C ++ variables in other classes, you need to add the constraint character "public" before defining the statement. In C ++, we have seen the following:

 
 
  1. Bool;
  2.  
  3. If (A=Getnum() // Assume that Getnum returns an integer.
  4.  
  5. {
  6.  
  7. // A is not 0
  8.  
  9. }
  10.  
  11. Else
  12.  
  13. {
  14.  
  15. // A is 0
  16.  
  17. }

A and B are all public, because public: is used, but such a statement is absent in C ++. I personally think this is actually good, concise, and clear, in C ++, you must add a delimiter to each variable:

 
 
  1. Using System;
  2.  
  3. Namespace ConsoleApplication1
  4.  
  5. {
  6.  
  7. Class Class1
  8.  
  9. {
  10.  
  11. Static void Main (string [] args)
  12.  
  13. {
  14.  
  15. Int [,]A1=NewInt [2, 2] {1, 2}, {3, 4 }};
  16.  
  17. Foreach (int B 1 in a1)
  18.  
  19. {
  20.  
  21. Console. WriteLine ("{0}", b1); // operations on the unchanged long array
  22.  
  23. }
  24.  
  25. Int [] []A2=NewInt [2] [];
  26.  
  27. A2 [0] = new int [2] {0, 1 };
  28.  
  29. A2 [1] = new int [3] {3, 4, 5 };
  30.  
  31. Foreach (int [] B 20 in a2)
  32.  
  33. {
  34.  
  35. Foreach (int B 21 in b20)
  36.  
  37. Console. WriteLine ("{0}", b21); // operations on the variable-length Array
  38.  
  39. }
  40.  
  41. }
  42.  
  43. }
  44.  
  45. }

The const keyword is used for constant definition, which is similar to C ++. it differs from read-only delimiters. 1. constant is static 2. you must assign values during initialization and do not understand the actual meaning. It is found that C ++ variables are also a cumbersome language. The above four operators can be used in insecure code of C ++ variables, but they are incorrect in General C # code. C # removes the pointer, operators related to pointers cannot be used.

  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

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.