0% found this document useful (0 votes)
74 views3 pages

CS214 - Programming Fundamentals: Quiz 2

The document is a quiz question from a programming fundamentals course assessing understanding of pointers in C++. It provides the student ID of the test taker, 20F-0531, and instructs them to use that ID in the code examples. The code examples demonstrate pointer operations like assigning values using pointers, incrementing pointers, and dereferencing pointers to modify array elements. The student is asked to trace the code and provide the contents of the array after each line is executed.

Uploaded by

Zain Mehmood
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views3 pages

CS214 - Programming Fundamentals: Quiz 2

The document is a quiz question from a programming fundamentals course assessing understanding of pointers in C++. It provides the student ID of the test taker, 20F-0531, and instructs them to use that ID in the code examples. The code examples demonstrate pointer operations like assigning values using pointers, incrementing pointers, and dereferencing pointers to modify array elements. The student is asked to trace the code and provide the contents of the array after each line is executed.

Uploaded by

Zain Mehmood
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Student ID: 20F-0531 Section: A Name: Zain Mehmood

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 {1,3,5,0}
Write the values of D1, D2,
D3, and D4

int a = 5; Garbage store the value 5 in a

0 x your ID
int *ptr = &a; 0x20F-0531 now initial a pointer to find address of a
0x20F0531

ptr = &arr[0]; 0x20F1 now address of 0 index of array

*ptr = 12; address is equal to the 12

++ptr;

*ptr = *ptr + 5; 17

ptr = ptr + 1; 0x20F2

*(++ptr) = 40;

ptr = arr;

*(ptr+4) = 60;

++(*ptr);
ptr = ptr + 4;

You might also like