Wednesday, May 2, 2007

Basic Features

Stream : It is a flow of data to and fro.
Standard Input Stream
Used to read data form Standard Input device i.e. keyboard ,it can take input from a file stored at hard disk and from other input devices also.
'cin' represents the Standard Input Stream.
Standard Output Stream
Used to send output to Standard Output Device i.e. Monitor, it can send output to file on hard-disk,printer etc.
'cout' represents the Standard Output Stream.
Standard Error Stream
Another output stream used by programs to output error messages.
'cerr' represents the Standard Error Stream.

The iostream is an object-oriented library that contains input and output streams.

C++ provide two ways to work with streams :
low-level
high-level
Very soon we will get detailed description of this topic...

C++ Comments
Single line comment
// single line statement here
Multiline Comment
/*
Some lines here
*/

References

C++ references are to create alternative name or alias name for the already defined variable.
for example :
int i = 18;
int &ref = i;
here ref is reference to integer variable i. it can be used in place of i.
->& is not address operator here, it is reference operator.<- REMEMBER :

* No memory is allocated for reference variables as they are alias name for simple variables.
* Reference variables should be initialized.

Main Use :
* as a formal argument to a function.
Example :
--------------------------------------
#include
using namespace std;
int Square(int &Val);
int main()
{
int Number=10;
Square(Number);
cout<<"Number is "<<>Pointer Reference:
It is Alias name to the pointer.

Example:
int ival = 100;
int *ptr = &ival;
int * &refptr = ptr;

Scope Resolution Operator :
In C a local variable has precedence over global variable with the same name.
In C++, global variable can be accessed through Scope Resolution Operator :: ,with local variable.
Example:

int i = 4;
int main()
{
int i = 9;
cout<< ::i<< endl; //Prints global variable i 4
cout<< i; //Prints local variable i 9
}
}