Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
50 views

Sanchit Sir Yash Sir: Visit Our Website

Here are the solutions to the questions: 1) The number of times printf statement is executed is 10. There is no break statement in the switch case, so cases 1, 2 and 3 will all be executed for i=2 and i=3. 2) The output will be 53 65. The integer literal 065 is octal and equivalent to decimal 53. 3) The output will be 70. The question is calculating arr[1] + arr[2] which is 20 + 50 = 70. 4) The number of function calls will be 25. The recursion tree has been drawn out to show this. 5) The expression float a = 85 / 0 will return Infinity.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Sanchit Sir Yash Sir: Visit Our Website

Here are the solutions to the questions: 1) The number of times printf statement is executed is 10. There is no break statement in the switch case, so cases 1, 2 and 3 will all be executed for i=2 and i=3. 2) The output will be 53 65. The integer literal 065 is octal and equivalent to decimal 53. 3) The output will be 70. The question is calculating arr[1] + arr[2] which is 20 + 50 = 70. 4) The number of function calls will be 25. The recursion tree has been drawn out to show this. 5) The expression float a = 85 / 0 will return Infinity.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Visit our website

Download KG App

SANCHIT SIR YASH SIR


PLACEMENT DAILY PRACTICE PROBLEM 4

Q1.
Consider the following C program:
# include <stdio.h>
int main( )
{
int i, j, k = 0;
j = 2 * 3 / 4 + 2.0 / 5 + 8 / 5;
k -= --j;
for (i = 0; i < 5; i++)
{
switch(i + k)
{
case 1:
case 2: printf("n%d", i + k);
case 3: printf("n%d", i + k);
default: printf("n%d", i + k);
}
}
return 0;
}
The number of times printf statement is executed is :

a.8
b.9
c.10
d.11

GATE-CS-2015 (Set 3)

TCS NQT Superset course

Programming Course for Placements, GATE and Interview


SANCHIT SIR YASH SIR
Q2. What will the output after execution of the following statements?

1. void main()
2. {
3. int i = 065, j = 65;
4. printf ("%d %d", i, j);
5. }

1. 065 65
2. 53 65
3. 65 65
4. Syntax error

(Topic – C programming)
(Asked in Elitmus 2018)

Q3. What will be the output of the following pseudocode?

Integer arr[]={10,20,50,40,60}

Integer a, s

Set s = 0

Set a = arr[1] + arr[2]

Print a

A) 25
B) 5
C) 50
D) 70

(Topic – Pseudo code)


(Asked in Infosys 2015)

Learn all about Python Programming

University Exam Preparation Course


VINAY SIR SANCHIT SIR
Q4. Consider the following recursive C function. If get(6) function is being called in main() then how
many times will the get() function be invoked before returning to the main()?
void get (int n)
{
if (n < 1) return;
get(n-1);
get(n-3);
printf("%d", n);
}
a. 15
b. 25
c. 35
d. 45

(GATE 2015)
Q5. What does the expression float a = 85 / 0 return?

a.0
b.Not a Number
c.Infinity
d.Run time exception

(Topic – Java programming)


(Asked in Microsoft 2019)

ANSWER KEY
S.No 1 2 3 4 5

Correct Opt c b d c c

Competitive Programming for beginners

Top 20 Coding questions for placements


SANCHIT SIR CHIRAYU SIR
SOLUTIONS -

1 Answer (c)
1. Explanation:
2. The following statement makes j = 2
3. j = 2 * 3 / 4 + 2.0 / 5 + 8 / 5;
4. The following statement makes k = -1.
5.
6. k -= --j;

7. There is one important thing to note in switch is, there is no break. Let count of printf statements be 'count'
8. For i = 0, the value of i+k becomes -1, default block
9. is executed, count = 1.

10. For i = 1, the value of i+k becomes 0, default block

11. is executed, count = 2.

12. For i = 2, the value of i+k becomes 1, all blocks are

13. executed as there is no break, count = 5

14. For i = 3, the value of i+k becomes 2, three blocks

15. after case 1: are executed, count = 8

16. For i = 4, the value of i+k becomes 3, two blocks

17. are executed, count = 10

2. Answer: (b) 53 65
Explanation: This value (065) is an octal value, and it equals to the decimal value 53.

3. Answer: C
Explanation:

There is an array of integer arr[]={10,20,50,40,60}. There are two variables a and b declared. .
The value initialized for s is 0. On next line adding the 1st index value 20 and 2nd index value 30
arr[1] + arr[2]( 20+50) the answer is 70 will be stored in a. Finally printing the updated values of a
is 70.
4. Answer: (b)

18. Explanation:
19. get(6) [25 Calls]

20. / \

21. [17 Calls] get(5) get(3) [7 Calls]


22. / \
23. get(4) get(2)[5 Calls]
24. / \
25. [7 Calls] get(3) get(1)[3 Calls]
26. / \
27. get(2) get(0)
28. / \
29. [3 Calls]get(1) get(-1)
30. / \
31. get(0) get(-2)

We can verify the same by running below program. [sourcecode language="CPP"] # include int count =
0; void get (int n) { count++; if (n < 1) return; get(n-1); get(n-3); } int main() { get(6); printf("%d ", count);
} [/sourcecode] Output: 25

5. Answer: (c) Infinity


Explanation: In Java, whenever we divide any number (double, float, and long except
integer) by zero, it results in infinity. According to the IEEE Standard for Floating-Point
Arithmetic (IEEE 754), if we divide 1/0 will give positive infinity, -1/0 will give negative
infinity, and 0/0 will give NaN. But on dividing an integer by zero, it throws a runtime
exception, i.e., java.lang.ArithmeticException.

Hence, the correct answer is an option (c).

Check FREE classes for GATE2022 on unacademy

Subscribe to Unacademy PLUS full course for GATE 2022


To get 10% discount on GATE 2022 Full course,

Use referral code

KGYT
on

SUBSCRIBE FOR FULL COURSE

Telegram group links

Placement group GATE discussion group

VISIT OUR WEBSITE


YASH SIR SANCHIT SIR

You might also like