Wednesday, October 3, 2012

C++ Variables

Variables are memory locations where you will store a data. There are several data types a variable can contain. Among the following in C++ are: int, char, float, double and bool.
int - are for integer data types. It is used to contain whole number integers.
char - are for characters. You will see examples later.
float - for integers with decimals.
double - for integers with decimals.
bool - for boolean. True or False;

To declare a variable in C++, this is the format: data_type name
int x;
float y;
bool tf;

You can also declare multiple variables with the same data type:
int x,y,z;

The name of the variable is case sensitive. Var1 is different from var1.

To Initialize a variable:
int x=0;

or declare then initialize:
int x;

Next: if, if else statements

No comments:

Post a Comment