Declaring a variable in C++
Written by cooldaves99us on Thu Dec 29, 2011 8:11 pm in blog MY PROGRAMMING BLOG under C++ -
184 views
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;
float grade;
char letter;
char* address;
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.
enjoy.
Happy programming...!!
0 blog comments below