oop-2-04042020-114726am.docx - Object Oriented Programming Lab CSL 210 Lab Journal Lab 2 MALIK UMAIR SAJJAD 01-134192-029 BSCS 2A Department of Computer

# oop-2-04042020-114726am.docx - Object Oriented Programming...

This preview shows page 1 - 6 out of 17 pages.

Object Oriented Programming Lab CSL 210 Lab Journal Lab # 2 MALIK UMAIR SAJJAD 01-134192-029 BSCS 2A Department of Computer Sciences BAHRIA UNIVERSITY, ISLAMABAD Review of C++ - Pointers, Dynamic Memory Allocation & Structures Objectives: Following programming skills will be acquired in this lab: To understand the use of a pointer. To use the Reference (&) and Dereference (*) operators. To understand pointer arithmetic. To understand relationship between a pointer and an array. To understand Dynamic Memory Allocation. To practice use of new and delete operators. To understand the use of a structure. To understand the syntax of defining a structure. To understand manipulation of structure members. To understand and use pointers to structures. To define and use nested structures. Tools Used: Visual studio 2017 Submission Date: 26-Feb-2020 Evaluation: Signatures of Lab Engineer: Task 1Write a C++ program that declares int variables x and y and int* pointer variables p and q. Set x to 2, y to 8, p to the address of x, and q to the address of y. Then print the following information: (1) The address of x and the value of x. (2) The value of p and the value of *p. (3) The address of y and the value of y. (4) The value of q and the value of *q. (5) The address of p (not its contents!). (6) The address of q (not its contents!). Procedure/Program: #include<iostream> #include<conio.h> using namespace std; int main() { int x, y; int *p; int*q; x = 2; y = 8; p = &x; q = &y; cout << &x<<endl; cout << x<<endl; cout << p << endl; cout << *p<<endl; cout << &y<<endl; cout << y<<endl; cout << q<<endl; cout << *q<<endl; cout << &p<<endl; cout << &q<<endl; _getch(); return 0; }   #### You've reached the end of your free preview.

Want to read all 17 pages?

• Spring '16
• saima
• Pointer
• • • 