Student ID: Section: Name:
CS214 – Programming Fundamentals
Quiz 2
Spring 2021
Time Allowed: 20 Minutes 2 April 2021 Maximum Marks = 10
The use of mobile phones and any other helping material is strictly forbidden
CLO No. CLO Statement Domain Taxonomy Level
2 Write C++ programs that employ the use of pointers, and structures (records). Cognitive 3
Question Number 3 (CLO 2) [10 Marks]
Details of your student ID will be used while answering this question.
4th 3rd 2nd 1st
Digit Digit Digit Digit
X X F - D4 D3 D2 D1
For example, if your student ID is 20F-0318, then D1 = 8, D2 = 8, D3 = 3 and D4 = 0. And you will use 0318 as your student ID.
Apply the concept of pointers to write the output of the following code. All the instructions will be executed in sequence and there are no syntax errors.
Suppose that:
The array element with index 2 is stored at the address 0x22fe38
The variable “a” is stored at address = your student ID.
Address Stored in
Code Line Contents of Array Reason/Explanation
Pointer
{D1, D2, D3, D4}
int arr[4]={D1, D2, D3, D4}; Garbage Write the values of D1, D2,
D3, and D4
int a = 5; Garbage
int *ptr = &a; 0 x your ID
Write your id here
ptr = &arr[0];
*ptr = 12;
++ptr;
*ptr = *ptr + 5;
ptr = ptr + 1;
*(++ptr) = 40;
ptr = arr;
*(ptr+4) = 60;
++(*ptr);
ptr = ptr + 4;