C++ data types, Variables, Declaration of variable, types of variable, Initialization Of variables


Variables

A variable is a memory location that is used to store values.

Example


Here age is the name given to memory location AFXX011 and is called the variable age.
We shall see how to declare a variable discussing data types

How do we use Variables?


In order to be able to use the memory location as a  variable, we need to declare it is allocate memory to it.
A variable can be declared using a data type and a
valid identifier.

What is a Data Type?

A data type defines a set of values and the operations that can be performed on that data.

Why do we need a data type?


As all of you must be aware that a computer is just a machine. It cannot by itself distinguish between various types of Data. This means that it cannot distinguish between the number 20 and the letter ‘A’ or the word  “good”. For the computer, all of this is just a piece of data.
It is the programmer who must tell the computer that 20 is a number, ‘A’  is a character and ‘good’ is a word. How do we do it?
By using data types we can classify the different data for the computer so that it can be stored and processed in a certain manner.

C++ Data Types : Categories

built in ---------- char,string,float,
user-defined and Derive datatypes

Declaration vs Initialization

When a variable is given a value at the time of  declaration itself this is known as initialization

int num;
int num=89
Variables are not automatically initialized. For  example, after declaration
int sum;
the value of the variable sum can be anything  (garbage).
Thus, it is good practice to initialize variables when they are declared.


Constant declarations

Constants are used to store values that never change during the program execution.
Using constants makes programs more readable and maintainable.

Syntax:


const data type identifier = value;
Examples:
const double rate = 7.8;

const int x= 45;


Don't forget to Like, Share, Comment and Subscribe this Channel.

Regards ITIANS
--------------------------------------Important Links-------------------------------------------

Facebook Page Link
https://www.facebook.com/Itians-465691327263016/

Google Plus Link
https://plus.google.com/u/0/b/116077931488499202137/communities/106048393986156245120

Twitter Link
https://twitter.com/ITIANS1

Comments