Skip to main content

Declaration Of Variables

Declaration Of Variables:

                                             Assigning the name and data type that a variable can hold is called declaration of the variable.All variables that are used in a program are declared using variable declaration statement.

             The syntax to declare a variable in c++ is:

             type list of variables;
where

type:
         specifies data type of variables.For example,it may be int,float,etc.

list of variables:
                       specifies a list of variables separated by commas. In a single statement more than one variables,separated by commas, of same data type can b declared.
                     
                      Different statements are used to declare variables of different data type.

                      For example, to declare variables"abc","xyz","w"and "A" of integer  type  the statement is written as:

       int abc ,xyz ,d w,A;

     To declare variables a and xy as int type,w as float type,nm as string type of 15 characters and sum as double, the statments are written as:


    int a,xy;
   
   float b;

   char nm [15];

   double sum;

Comments

Popular posts from this blog

Programs

PROGRAM 1: #include<iostream> using namespace std; int main() {    cout<<"HELLO WORLD";    return 0; } OUTPUT OF THE PROGRAM: HELLO WORLD                 ............................................................................................................................. PROGRAM 2: #include<iostream> using namespace std; int main() {    cout<<"c++ is best language";    return 0; } OUTPUT OF THE PROGRAM: c++ is best language      .............................................................................................................................                    

Initialization Of Variables

Initialization Of Variables:   When a variable is declared,a memory location is assigned to it.The value in that memory location is  also assigned to the variable.This preassigned value of a variable,if not used by mistake,may result in incorrect result.To avoid this situation, a known value is  assigned to the variable.This value is assigned to the variable at the time of its declaration.Assigning a known value to a variable at the time of its declaration is called initializing of the variable.        For example, to declare variables a,b and c of integer type and assigning values a=220 and b=70,the statement is written as:            int a=220,b=70,c;