What is the output of the following code fragment? int v1 = 2, v2--1; int *pi: i
ID: 3593475 • Letter: W
Question
What is the output of the following code fragment? int v1 = 2, v2--1; int *pi: int *p2; 5. p2 = p1; printf("%d %d", a) -12 b) 2-1 22 d) ·1-1 e) None of above *p1, *p2); Question 6 and 7 refer to the following recursive method: int compute (int x, int y)f if (xy return xi else return (compute (x+1, y-1)) 6. Which is returned by the call compute (1, 5)? a) 1 b) 2 c) 3 No value is returned because an infinite recursion occurs. 7. Which of the following calls leads to an infinite recursion? 1. cpute (2,8) II. compute (8, 2) III. compute (2, 5) a) I only b) Il only III only I and H I and IIIExplanation / Answer
5 )
Ans: b) 2 -1
As p1 is the pointer which has address of v1 and p2 is the integer pointer which has address of variable v2.
*p1 will access the content of memory address pointed by p1
*p2 will access the content of memory address pointed by p2
6)
Ans: c) 3
7)
Ans : e) II and III
In the recursive function of compute,, recursive condition is when x and y bcomes equal then it is returned from function.. First number should be less than second number and difference between first and second number must be even number for the recursive function to work by lookking at the code of the recursive function.. Otherwise recursive function never returns.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.