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

Object Oriented Programming Assignment # 02: Submitted To

This document contains an assignment submission for an Object Oriented Programming course. It includes: 1) A cover page with the student's name, registration number, submission date, and course details. 2) A question on pointers and how they are implemented in programming. The student defines pointers as variables that hold memory addresses and discusses how they are defined and used. 3) A second question asking the student to write a program demonstrating the use of pointers with structures and functions, and to mention the output. The student provides the source code for a program that defines a structure with pointer variables, gets user input in main using pointers, and passes the values to a function to find the largest number and output the result

Uploaded by

Ibtsaam Elahi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

Object Oriented Programming Assignment # 02: Submitted To

This document contains an assignment submission for an Object Oriented Programming course. It includes: 1) A cover page with the student's name, registration number, submission date, and course details. 2) A question on pointers and how they are implemented in programming. The student defines pointers as variables that hold memory addresses and discusses how they are defined and used. 3) A second question asking the student to write a program demonstrating the use of pointers with structures and functions, and to mention the output. The student provides the source code for a program that defines a structure with pointer variables, gets user input in main using pointers, and passes the values to a function to find the largest number and output the result

Uploaded by

Ibtsaam Elahi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

MTE-203

OBJECT ORIENTED PROGRAMMING


Assignment # 02
Submitted to:
Fadia Sohail
Submitted by:
Ibtsaam Elahi
Registration no:
UW-20-MTS-BSC-008
Submission date:
29th Oct,2021
Department of Mechatronics Engineering
Wah Engineering College
Wah Cantt

Ibtsaam Elahi UW-20-MTS-BSC-008


(Question # 01)
What are Pointers? How they are implemented in Programming.

Pointers:
Pointer is a variable in C++ that holds the address of another variable. They
have data type just like variables, for example an integer type pointer can hold the address of
an integer variable and an character type pointer can hold the address of char variable. Dealing
with these memory addresses in programming is done by pointers. Pointers are extremely
powerful programming tool that can make things easier and help to increase the efficiency of
a program and allow programmers to handle an unlimited amount of data. It is possible for
pointers to dynamically allocate memory, where programmers don't have to worry about how
much memory they will need to assign for each task, which cannot be done/performed without
the concept of a pointer.

Syntax of pointer
data_type *pointer_name;

❖ Implementation of pointers:
There are some important points to implement pointers:
➢ Define a pointer variable
➢ Assigning the address of a variable to a pointer using unary operator (&) which returns the
address of that variable.
➢ Accessing the value stored in the address using unary operator (*) which returns the value
of the variable located at the address specified by its operand.

Benefits of using pointers in programming

➢ Pointers save the memory.


➢ Pointers reduce the length and complexity of a program.
➢ Pointers allow passing of arrays and strings to functions more efficiently.
➢ Pointers make possible to return more than one value from the function.
➢ Pointers increase the processing speed.

Ibtsaam Elahi UW-20-MTS-BSC-008


(Question # 02)
Write a program that defines the use of pointers with Structures and
Functions. Also mention the output.
In this program I will define a pointer in structure and then make object of structure in main
function. And do operation in any user define function. So

❖ Source code:
#include<iostream>
using namespace std;
int lareg(int,int);
struct larg{
int *large;
int *xptr;
int *yptr;
};
int main()
{
larg r;
int x,y;
cout<<"Enter the value of
x :";
cin >> x;
cout<<"Enter the value of
y :";
cin>> y;
r.xptr=&x;
r.yptr=&y;
lareg(x,y);
}
int lareg(int a,int b)
{
int large;
if(a>b)
large=a;
else
large=b;
cout<<"The largest
nmuber is :" <<large;
}

Ibtsaam Elahi UW-20-MTS-BSC-008


❖ Output Window:

Thanks

Ibtsaam Elahi UW-20-MTS-BSC-008

You might also like