* New post Constructor Destructor and Inheritance& Array , Virtual base class in c++ language

Sunday, 23 March 2014

0 C++ constants , variables

C++ constants 
Any fixed data item that does not change during the execution of the program is known as constant. The constants in c++ language are classified as :-


  • Integer Constants : An integer constant is a number without any decimal point . The integer constants may be of positive and negative sign. There are three types of integer constants :
  1. Decimal : A decimal integer may be positive or negative , it does not have a decimal point , commas . Ex : +50 , 256 , -501, 0, are valid integers.
  2. Octal integer : The first digit of the octal number must be 0. It does not have a decimal point , commas, and blank spaces. Ex : 050 , 043 , 070, are valid octal integers.
  3. Hexadecimal Integer : A hexadecimal integer begin with o X and o X , it is collection of digits 0 to 9 and alphabets ( A to F). Ex : 0 X 1 , 0 X A1 etc.


  • Floating point constant : The numeric value with a decimal point is called  Floating point constant . It may be positive or negative signed or unsigned . Ex : +36.40 , 140.50 , -541.41 , 123.145 etc.
  • Char constants : Any char with in a single quote is called Char constant. Each char has a specific code value given by ASCII code (American standard code for information interchange ). Ex : 'a',  's' , '@' , '* ' etc.
  • String : A string is a collection of two or more char enclosed within a double quotes. Ex "computer" , " Rs 2500 " , " www.programmingking.in " .


Variables

A  variable is an entity used to store a single value (data ) at a time . The value of variable can be change during the execution of  the program. A variable can store different values at different time during the execution of the program. Also we can say that a variables identifying the memory location where the data is stored .

Declaration of variable : data type variable 1 , variable 2 ----------- ;
The variable are declared at the beginning of the program. The compiler reserves the memory space according to type of variable so that the data can be stored , accessed and modify in the memory. Ex:
                                                                      Int num , s, t ;
                                                                      float height ; 

  • Preprocessor : It is a program that runs firstly before the execution of the main program. The preprocessor command start with a symbol # . The preprocessor are used for including the header file and defining the macros. 
  • C++ headers files : The header file that specially used in c++ , is " iostream.h " . This header file helps to perform input/ output operations. The role of the header file ( studio .h) in c language . The file contains the code or definition of objects cout and cin and the input operator >> , output operator <<.
  • Input / Output Headers : CAscading of I/O operators : When  an input operator or an output operator appears more then one time in a single statement then it is called Cascading of I/O operators.

Ex : Cout <<" Net salary ="<<net << end l  , Cin >> basic >> TA >> DA ;
Initialization of Variables 
When we assign the value to the variable , then this assignment of value to the variables is known as variable initialization . We can initialize variable at the time of declaration and also we can initial the value to variables after declaration.
Ex :
# include <iostream .h>
# include <conio.h>
{
       Int Basic =5000, TA =250,DA, HRA, Net;
       clrscr ( );
       DA = 300;
                 HRA =500
                 Net = basic + TA + DA + HRA;
                cout <<" net salary ="<< net ;
                getch ( ) ;
 Reference Variable : A reference variable provides an alternative for a previously defined variable. If we make a variable as a reference to other variable . Then both the variable can be used for the same value also if we modify value in a variable then the value is modified in other variable . we can declare a reference variable as : data _ type & reference _name = variable name ;
Ex: 
     void main ( )
{
    int a = 50;
   int &b = a;
            cout << " initial value of a = "<<a <<"and b="<<b<<endl;
             a = a+ 10 ;
             cout << " After first change in a " << "a = "<< a<< " and b=" << b << end l;
             b = b+100;
            cout <<" after change in b " << a = " << a << " and b = " << b << end l.;
             getch ( ) ;
         } 





0 comments:

Post a Comment

 

PROGRAMMINGqueen Copyright © 2011 - |- Template created by O Pregador - |- Powered by Blogger Templates

Blogger Widgets