Lab Report 11
Lab Report 11
240201010
Lab Report 11
PROGRAMMING FUNDAMENTALS
Lab Task 1 :
C++ Statement :
#include <iostream>
int main() {
ptr = &var1;
var1 = 10;
*ptr = 20;
return 0;
Output :
Lab Task 2 :
Output :
Lab Task 3 :
C++ Statement :
#include <iostream>
using namespace std;
int main() {
int x = 10, y = 20;
cout << "Before Swap: x = " << x << ", y = " << y << endl;
swap(&x, &y);
cout << "After Swap: x = " << x << ", y = " << y << endl;
return 0; }
Output :
Lab Task 4 :
Write a C++ program that inputs four floating-point values and displays the memory
address of all the values using pointers. Also, display the values using pointers.
C++ Statement :
#include <iostream>
using namespace std;
int main() {
float val1, val2, val3, val4;
return 0;
}
Output :
Lab Task 5 :
Write a program that inputs a string value from user and displays it using pointer.
C++ Statement :
#include <iostream>
using namespace std;
int main() {
string str;
cout << "\nString using pointer: " << *ptr << endl;
return 0;
}
Output :
Lab Task 6 :
Write a C++ program that:
Creates an array of integers with 5 elements.
Uses a pointer to sum the elements of the array.
Prints the sum of the array.
C++ Statement :
#include <iostream>
using namespace std;
int main() {
int arr[5];
int *ptr = arr;
int sum = 0;
return 0;
}
Output :
Lab Task 7 :
Write a C++ program that:
Creates an array of integers with 10 elements.
Uses a pointer to traverse through the array and print each element.
Uses pointers to reverse the array and print the reversed array.
C++ Statement :
#include <iostream>
using namespace std;
int main() {
int arr[10];
return 0;
}
Output :
Lab Task 8 :
Write a C++ program that:
Defines a function swap() that takes two integer pointers and swaps the values of the
integers.
In the main() function, initialize two integer variables and pass their addresses to the
swap() function to swap their values.
Print the values before and after the swap
C++ Statement :
#include <iostream>
using namespace std;
int main() {
int num1 = 10, num2 = 20;
swap(&num1, &num2);
return 0; }
Output :