Professional Documents
Culture Documents
Total 20
REPORT VERIFICATION
Staff Name :
Signature :
EXPERIMENT-2
//RA2311043010081
#include <iostream>
using namespace std;
int main()
{
int a = 10;
int* pt;
pt = &a;
cout << "The address where a is stored is: " << pt<< endl;
cout << "The value stored at the address by dereferencing the pointer is: "<< *pt << endl;
}
OUTPUT:
2. Write C++ program to demonstrate the difference between call by value and call by reference:-
//RA2311043010081
#include <iostream>
// Function to demonstrate call by value
void callByValue(int x)
{
std::cout << "Inside callByValue function\n";
std::cout << "Original value of x: " << x << "\n";
// Modifying the value of x inside the function
x = 20;
std::cout << "Value of x after modification inside callByValue: " << x << "\n";
}
// Function to demonstrate call by reference
void callByReference(int &y)
{
std::cout << "Inside callByReference function\n";
std::cout << "Original value of y: " << y << "\n";
// Modifying the value of y inside the function
y = 30;
std::cout << "Value of y after modification inside callByReference: " << y << "\n";
}
int main() {
// Demonstrate call by value
int num1 = 10;
std::cout << "Before calling callByValue, num1: " << num1 << "\n";
callByValue(num1);
std::cout << "Value of num1 after calling callByValue: " << num1 << "\n";
// Demonstrate call by reference
int num2 = 15;
std::cout << "Before calling callByReference, num2: " << num2 << "\n";
callByReference(num2);
std::cout << "Value of num2 after calling callByReference: " << num2 << "\n";
return 0;
}
OUTPUT:
OUTPUT:
RESULT:
The Programs on Reference and Pointers were executed and desired output was obtained.