Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

My La ardia. Student X·-FINAL EXAM-2018 SprixyD FINAL DAMpdf C ?fie//cusers/b330

ID: 3912795 • Letter: M

Question

My La ardia. Student X·-FINAL EXAM-2018 SprixyD FINAL DAMpdf C ?fie//cusers/b330-u14/Downloads/FINAL%20EXAM pdf / What is the output produced by the following code? int pl, p2: pi10 p2-20 pi p2 p130; 12. Define a function called copyLine chat takes one argument that is an input stream. When called, copyLine reads one line of input from the input stream given as its argument and writes that line to the screen. You should be able to call your function using either cin or an input-file stream as the argument to your function copyLine. (If the argument is an input-file stream, then the stream is connected to a file before the function is called, so copyLine will not open or close any files.) For example, the first of the following two calls to copyLine will copy a line from the file atuff.txt to the screen, and the second will copy a line from the keyboard to the screen: itstream tin tin,open ("stuff.txt*) ; copyline (tin) i copyline (ein) ??

Explanation / Answer

The output of the above given code will be as follows:

10 20

20 20

30 30

The reason is:

During the first assignment both the pointers p1 and p2 will store their respective assigned values and the same will be printed i.e. 10 20

During second assignment i.e. p1=p2, the address stored in p2 will be copied in p1 and the value stored at that address is printed when it is dereferenced. Thus, 20 20

During the third assignment both the pointer store same address due to the second assignment and hence change made by one of the pointers will be reflected in both. Thus when the value at address stored in p1 is changed to 30, the value at p2 is also changed which contains the same address. Hence on dereferencing, the output will be the changed value for both the pointers i.e. 30 30

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote