Data Handling

 

Data Types

                                                   
Data Handling

Data Handling



Data Types


When we wish to store data in a C++ program, such as whole number or a character, we have to tell the compiler which type of data we want to store. Data type will have characteristics such as range and operations that can be performed on variables of that type.
1.    Fundamental data type
2.    Derived data type
3.    User defined


 Variables


A variable is a name for a place in the computer’s memory where you store some data.
For eg.  x=5 where value 5 is assigned to variable x.
Ex.  int i;
There are two bytes associated with a symbolic variable:
1.      Its data value, referred to as “rvalue”.

2.    Its location value, refered to as “lvalue”.

                          
data handling 





1. Declaration of a variable


Declaring a variable means giving name and type to the variable.
Ex.    int age;
         double pi;
         long double res;


2. Initialization


Initializing a variable means giving value to the variable.
Ex.       int p=36;
            int p(36);
            int p=int (36);  


3. Dynamic initialization

One additional feature of C++ is that, it permits initializing a variable at run time.
Ex.  int a, b;
       int sum;
       sum=a+b;  


References 


A reference is an alternative name for an object. A reference variable provides an alias for a previously defined variable. Reference variable is declared by &sign.

Ex.              int total;
     int &sum=total;
     total=50;
                   cout<<”sum is :”<< sum<<”\n”;
                   cout<<”Total=”<<"\n";
                    
 Output:   sum is: 50
 Total=50




This post is about Data Handling in C++. In the next post we will talk about Operators  and Expressions.

       




Post a Comment

0 Comments