"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain

Thursday, February 25, 2010

Write a C++ program that uses a function smallo() (that is passed two int argument by value) to receive reference of the smaller value. Then using this reference the smaller value is set to 0. Write a main() function also to exercise this function.

/* This is a example of return by reference */ 


#include<iostream.h>
#include<conio.h>

int &smallo(int a, int b)
{
if(a>b)
  return a;
else
  return b;
}


void main()
{
int a, b;
cout<< "\n Enter two numbers :";
cin >> a >> b;

cout<< "\n The original values :" << a << "  and " << b;

smallo(a, b) = 0;

cout<< "\n The changed values :" << a << " and " << b;



getch();
}

1 comment:

  1. yahan per choro main int ke bad & aur neche void main ke under smallo(a,b) = 0 kyun hai

    ReplyDelete

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.