Wednesday, October 19, 2011

Program:To illustrate concept call by value in c++




Call by value
CODE:

#include <iostream.h>
#include <conio.h>
void swap(int, int);
main()
{
clrscr();
int a, b;
cout << "Enter two numbers: ";
cin >> a >> b;

cout << "\nBefore Swapping:\n";
cout << "\na = " << a << " b = " << b;

cout << "\n\nAfter Swapping(call by value): \n";
swap(a, b);

getch();
}
void swap(int x, int y)
{
int t;
t = x;
x = y;
y = t;

cout << "a = " << x << " b = " << y;
}

Article by
Chief-Editor

He is a tech Enthusiast, an Altruist and calm mentor. He loves to code. He is also a creative graphic designer. Do check out his designfolio @ Jasmeet.asia If you like This post, you can follow me on Twitter.



For Further Reading,
C++ Program

0 comments:

Post a Comment