0% found this document useful (0 votes)
50 views

SYS Prog 2 1

The laboratory report describes experiments conducted on C++ programs using references and pointers. Three programs are presented: 1. A program demonstrating reference and dereference operators in pointers by printing the address and value of an integer variable. 2. A program showing the difference between call by value and call by reference by passing an integer to a function and observing the effect of modifications inside the function. 3. A program changing the value pointed to by a pointer by assigning a new value through the pointer and verifying it updated the original variable. The aim of developing and executing these programs was achieved as the desired output was obtained for all programs.

Uploaded by

sv8049
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

SYS Prog 2 1

The laboratory report describes experiments conducted on C++ programs using references and pointers. Three programs are presented: 1. A program demonstrating reference and dereference operators in pointers by printing the address and value of an integer variable. 2. A program showing the difference between call by value and call by reference by passing an integer to a function and observing the effect of modifications inside the function. 3. A program changing the value pointed to by a pointer by assigning a new value through the pointer and verifying it updated the original variable. The aim of developing and executing these programs was achieved as the desired output was obtained for all programs.

Uploaded by

sv8049
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Laboratory Report Cover Sheet

SRM INSTITUTE OF SCIENCE AND TECHNOLOGY


College of Engineering and Technology
Department of Electronics and Communication Engineering
21ECC112J– Systems Programming
II Semester, 2023 - 24 (Even Semester)
Name : SHRINIVAS V
Register No. : RA2311043010090
Class : ECE P-SEC
Venue : TP, 13th FLOOR, RF LAB (ROOM 1314)
Title of Experiment : Develop and practice C++ programs using References
and Pointers
Date of Conduction :
Date of Submission :

Particulars Max. Marks Marks Obtained


Pre Lab 05
Lab Performance 05
Post Lab 05
Record Submission 05

Total 20

REPORT VERIFICATION
Staff Name :
Signature :
EXPERIMENT-2

DEVELOPE AND PRACTICE C++ APPLICATION PROGRAMS USING REFERENCES POINTERS


AIM/OBJECTIVE: To write and execute C++ programs to demonstrate the use of Reference and Pointers
SOFTWARE USED: Online C++ Compiler
PROGRAMS:
1. Write a C++ program signifying reference and de-reference operators in pointers:-

//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:

3. Write a program to demonstrate changing the value pointed by pointers :-


//RA2311043010081
#include <iostream>
int main()
{
// Declare a variable
int originalValue = 10;
// Declare a pointer and initialize it to the address of the variable
int* pointerToValue = &originalValue;
// Display the original value and the value through the pointer
std::cout << "Original Value: " << originalValue << "\n";
std::cout << "Value through Pointer: " << *pointerToValue << "\n\n";
// Change the value through the pointer
*pointerToValue = 20;
// Display the updated values
std::cout << "Original Value after change: " << originalValue << "\n";
std::cout << "Value through Pointer after change: " << *pointerToValue << "\n";
return 0;
}

OUTPUT:
RESULT:
The Programs on Reference and Pointers were executed and desired output was obtained.

You might also like