Tuesday, May 5, 2015

Programe for reversing integer in c++

 #include<iostream>
using namespace std;

int main() {
int number, reverse = 0;
cout<<"Input a Number to Reverse and press Enter: ";
 cin>> number;     // Taking Input Number in variable number

   while(number!= 0)
   {
      reverse = reverse * 10;
      reverse = reverse + number%10;
      number = number/10;
   }
   cout<<"New Reversed Number is:  "<<reverse;
   return 0;

}

Sunday, April 19, 2015

C++ Programming

Use of sizeof()

This function is used for finding the size of any variable include array ,structure and class .

Syntax:

if we want to find the size of integer variable :

int a,b;
b=10;
a=sizeof(b);
cout<< b <<endl ;

or
cout <<sizeof(b)<<endl;

if we want to find the size of general data type :

cout<<sizeof(int)<<endl;
cout<<sizeof(float)<<endl;
cout<<sizeof(bool)<<endl;

OOP using c++

Pass by Reference Function Example

#include<iostream>//for cin and cout objects
using namespace std;//definition of cin and cout object lies in std namespace
void swap(int &a,int&b)//function prototype

//use address operator (this operator return the memory address of variable)
{
int temp;
temp=a;
a=b;
b=temp;
}
void main()
{
int x=2;
int y=4;
swap(x,y);
cout << x << endl ;
cout << y << endl ;
        system("pause");
}