Sunday, August 29, 2010

How to use Pointer in c tutorial | Pointers in Cplusplus | pointer in c language

,
What is Pointer?

Pointer is very important in C and C++. It's  a variable which stores memory of user type and primary variable. It Hold the value of memory of a variable.

Why we use Pointer?
Some time we need to storing the address of variable for solving this problem we use pointer which capable to storing the memory address of a variable.

Guideline for using pointer
1. Define * When we use pointer
2. when we store address of pointers of pointer then we use **variable name

Example of Pointer

#include<iostream.h>

int main ()
{
int first,second;
int * ptr;
ptr = &first;
*ptr = 10;
ptr = &second;
*ptr = 20;
cout << "first is " << first << endl;
cout << "second is " << second << endl;
return 0;
}

Output:- First is =10
Second is =20
Read more →

String Operations in cplusplus

,
String Handling:-A string is a collection of  characters.String is  a class in cplusplus and there are three constructors in the String class.
1.)String():-For creating an empty string
2.)String(Const char *str):-For creating a string object from a null terminated string
3.)String(const string &str):-For creating a string object from other string object

#include<iostream.h>
#include<string.h>
void main( )
{
char ch1[] = “Cplusplusexample”;
char ch22[80];
for(int i=0; i
ch2[i]=ch1[i];
ch2[i]=’\0’;
cout<< “The copied string is “<< ch2;
}
Output:-The copied string is Cplusplusexample
Read more →

Exception Handling in Cplusplus

,
Exception handling:-Exception Handling is used in object oriented programming.It is feature by which we can handle easily a lot of feature.so that u can easily debug the code and to find the where the actual problem reside.In the Exception Handling we can use the try and the catch block
In the try block we can use the code in which the error may be occured that are to be placed in try block.
In the catch block particular error are to be handled in which way.The solution of particular error are provided in the catch block.
Example:-
#include<iostream.h>
int  main()
{
int a,b;
cout<<”Enter Values of a and b\n”;
cin>>a>>b;
int x=a-b;
try
{
If(x!=0)
{
cout<<”Results(a/x)=”<<<”\n”;
}
else
{
 throw(x);
}
}
catch(int i)
{
cout<<”Exception Caught :x=”<<<”\n”;
}
cout<<”END”;
return 0;
}

Output1:-            Enter Values of a and b
                                400       20
Result(a/x)  =   20
END

Enter Values of a and b
                                20           20
Exception Caught:   x =   0
END


Read more →

Thursday, August 26, 2010

Vectors

,
Read more →

Function overriding in c++ | What is Function overriding

,
Read more →