Declaring a variable in C++ is very simple
In computer programming we will be manipulating a value.
In order to manipulate a value we will store it temporarily to a variable which is used as reference in the memory.
Before using a variable we must declare it first.
In declaring a variable we must used a data type.
The following are primitive data types
int - this is used if the value are whole numbers. ex. 100
float - this is used if the value has fractional parts. ex. 38.9
char - this is used if the value has a single character only.
char* - a pointer to a char, this is used if the value are more than one characters.
To declare a variable:
Syntax: data_type variable_name;
ex. int number;
if we want to assign a value to a variable we will be using the assignment operator (=)
ex. number = 10;
grade = 90.10;
letter = 'a';
address = "Philippines";
That is how easy the variable declaration in C++ and how to assign a value to it.
0 blog comments below