C + + Basics Tutorial-variables

Source: Internet
Author: User

Second, variable

program processing of data, generally through the external keyboard input, first to put into the memory of the different units, this is the variable, let's look at a practice;

1, start Geany

1 point Menu "application-programming-geany" Start Geany, create a new C + + source program;

2 Point Menu "file-Save as" command, to "Bianliang" as the filename, save the file to its own folder;

2, input program code

1 in the Blue Code area below, enter a line int A;

#include <iostream>

using namespace Std;

int main (int argc, char** argv)

{

int A;

return 0;

}

2 This line defines a variable a, and the preceding int represents an integer variable that holds integers, char, and only one letter,

This is the equivalent of having a cup of water, small or large, to buy as needed;

2. Assigning values to variables

1) Then click the ENTER key to the next line, enter a = 20;

int A;

A = 20;

3 This line is to assign a value to the variable a, the value can be more than the maximum size according to the type of variable to decide,

The equivalent of pouring water into a cup, fill a cup at most, and more will overflow;

4) to the next line, enter cout << A; Show the value of a, the equivalent of a cup to take a look at;

int A;

A = 20;

cout << A;

Save, compile, build, run, and see the results of the display;

5 Return to continue to enter the following content, to assign the variable value, the equivalent of a glass of water poured;

int A;

A = 20;

cout << a << Endl;

A = 6;

cout << A;

6 save, compile, build, run, at this time a store is 6;

7 in general, the variable is like a box, which can be loaded, can be reused, but after the contents will cover the front;

Definitions and assignments can be performed together, for example int a = 20; is also very good;

#include <iostream>

using namespace Std;

int main (int argc, char** argv)

{

int A;

A = 20;

cout << a << Endl;

A = 6;

cout << A;

return 0;

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.