Programming Fundamentals Important Programs
Programming Fundamentals Important Programs
PROGRAMMING
FUNDAMENTALS LAB
LAB TASKS 11
CODE:
OUTPUT:
QUESTION 2:
What will be the output of the following code?
#include<iostream> using namespace std; void main() { int
nNumber; int *pPointer; nNumber = 15; pPointer =
&nNumber; cout<<"nNumber: "<<nNumber <<"\npPointer:
"<<pPointer <<"\n*pPointer: "<<*pPointer <<"\n&nNumber:
"<<&nNumber <<"\n&pPointer: "<<&pPointer
<<"\n&*&*pPointer: "<<&*&*pPointer <<"\n*&*&*pPointer:
"<<*&*&*pPointer<<endl;
CODE:
OUTPUT:
QUESTION 3:
Write a C++ program that use pointers to swap two integer
values.
CODE:
OUTPUT:
QUESTION 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.
CODE:
OUTPUT:
QUESTION 5:
Write a program that inputs a string value from user and
displays it using pointer.
CODE:
OUTPUT:
QUESTION 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.
CODE:
OUTPUT:
QUESTION 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.
CODE:
OUTPUT:
QUESTION 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.
CODE:
OUTPUT: