Sanchit Sir Yash Sir: Visit Our Website
Sanchit Sir Yash Sir: Visit Our Website
Download KG App
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)
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)
Integer arr[]={10,20,50,40,60}
Integer a, s
Set s = 0
Print a
A) 25
B) 5
C) 50
D) 70
(GATE 2015)
Q5. What does the expression float a = 85 / 0 return?
a.0
b.Not a Number
c.Infinity
d.Run time exception
ANSWER KEY
S.No 1 2 3 4 5
Correct Opt c b d c c
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.
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. / \
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
KGYT
on