3. CPP-Statements

CPP-Oops Concepts: Previous                                  Next: CPP Programming Examples
Comments are used to provide understandability of the written program. All the elements are ignored by the compiler at the running time or execution time of the program. In previous Eg. The statement with double slash(//) is a comment. Comments can be written in multiline also. The notation is: /*----------*/
Eg:   /* Example of
             Comment */
2. Preprocessive directive or include file:
Header file contains all the library functions and their syntaxes. Like in C the header file is used same in C++ file is used which contains all input/output library function such as cout, cin.
‘#include’ is refer to as “Preprocessor directives”. 
3. Console input/output:
Console output: to display onto the output screen. The keyword “cout” followed by “insertion” operator is used to display string on screen.
           Eg: cout<<“the Example of Console Output”;
Console input: to take input from the keyboard, console input is used. The word “cin” with extraction operator (>>) is used.
        Eg: cin>>a;
In above statement, the inputted data will stored in specified variable name.
More than one value can be taken by specifying multiple variables in single statement.
Eg:   cin>>a>>b;
Basic concept different from C :
  • Reference variable
  • Operators in c++ &
  • Friend function
What is a Reference variable?
  • This is new kind of variable provided by c++.
  • This variable is used to give alias or alternative name to defined variables.
    • Predefined variables like int,float, char ,double are same as in C.
  • Suppose we have declared a variable named ‘count’ as of intdatatype and now made a variable named ‘count1’ as a reference variable of named ‘count’. Then both can be used interchangbly at each other place.
  • Syntax :
Datatype& reference variable name=variable name;
                                For  Example :
                                                float count=10;
                                                float &count1=count;

  • After making a reference variable the statement :
will work same or will display 10 on screen.
  • If we change a value of either variable, then both value will get changed.
CPP-Oops Concepts: Previous                                  Next: CPP Programming Examples