05 – C++ : Variables

0
75

CplusplusIn C++, each variable has a specific type wherein it determines the layout of the variable’s memory and the size. Not just that, it also determines the range of values stored within that memory.

 

Variable can be consist of characters such as digits, letters, and even an underscore. It either begins with a letter or a digit. And because C++ is case-sensitive, the use of lowercase and uppercase are very distinct.

 

Below are the basic types of variable in C++:

 

Type Description
bool provide the true and false value
char it hold one character only either string and integer and etc.
int set numbers only
float determine numbers with the decimal point
double determine numbers with the decimal point
void Does not return any value.
wchar_t contains wide character type.

Example:

  • int i;
  • char name;
  • float total;
  • double amount;
  • bool result;

Executed program

for int

for char

for float

for double

for bool

 

C++ variable can also be declare in a group and its seperator is a comma(,).

Example

Note : when declaring a variable, you have to put a correct name for the action you want to perform to avoid misdirection.

Facebook Comments

LEAVE A REPLY

Please enter your comment!
Please enter your name here