Learn More

Wednesday, August 10, 2011

Data And Variables

cpp logo
Before you start using c + +, it is essential to know the basics of data types used in c + +. Important because it concerns the computer memory to be used and the success you run the program. For example, you might even make a double data type, but it could as type int. So in this situation you are said to consume too much computer memory. On the other hand, maybe you just use int data, but the program requires that you create a data type double. Then your program does not run properly. So by knowing the types of data that can be used in c + + would be very helpful at all the quality programs that you create. The types of data are int, double, long int, long double, char, short int, bool, float, wchar_t.

Variables

Any symbol that is specific to a particular data type, then the symbol will be variable. You can make more than one type of variable. When there are several symbols that have the same type of data, then we can write it into one command, but these symbols separated by commas.

First Way Writing Variables Second Way Writing Variables

int a;
int b;
int c;

int a, b, c;

The scope of variables

Inside the C + +, the position of the writing on the body of the program will determine the scope of the variables used. There are two types of variable scope that is, global variables and local variables.

variable scope of c++

Variable initialization

Each program needs to be initialized once, in c + + there are two ways to initialize. Please see the picture above carefully. Actually, there are two types writing initialization. First example by using "int a = 1" or second example by using "int a (1)".