CS214 - Programming Fundamentals: Quiz 2
CS214 - Programming Fundamentals: Quiz 2
2 Write C++ programs that employ the use of pointers, and structures (records). Cognitive 3
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
0 x your ID
int *ptr = &a; 0x20F-0531 now initial a pointer to find address of a
0x20F0531
++ptr;
*ptr = *ptr + 5; 17
*(++ptr) = 40;
ptr = arr;
*(ptr+4) = 60;
++(*ptr);
ptr = ptr + 4;