Following questions have been asked in GATE CS 2014 exam.
1) Consider the following program in C language:
Which one of the following statements is TRUE?
(A) Compilation fails.
(B) Execution results in a run-time error.
(C) On execution, the value printed is 5 more than the address of variable i.
(D) On execution, the value printed is 5 more than the integer value entered.
Explanation: There is no problem in the program as pi points to a valid location.
Also, in scanf() we pass address of a variable and pi is an address.
2) Consider the function func shown below:
The value returned by func(435)is __________.
Explanation: The function mainly returns position of Most significant bit in binary representation of n. The MSD in binary representation of 435 is 9th bit.
3) Consider the C function given below.
Which one of the following is TRUE?
(A) The function returns 0 for all values of j.
(B) The function prints the string something for all values of j.
(C) The function returns 0 when j = 50.
(D) The function will exhaust the runtime stack or run into an infinite loop when j = 50
Explanation: When j is 50, the function would call itself again and again as neither i nor j is changed inside the recursion.
4) Consider the C function given below. Assume that the array listA contains n (> 0) elements, sorted in ascending order.
Which one of the following statements about the function ProcessArray is CORRECT?
(A) It will run into an infinite loop when x is not in listA.
(B) It is an implementation of binary search.
(C) It will always find the maximum element in listA.
(D) It will return -1 even when x is present in listA.
Explanation: The program is a simple iterative C implementation of Binary Search.
5) Consider the following function
Give a value q (to 2 decimals) such that f(q) will return q:_____.
The main thing to note is the expression “abs(x*x – 3) < 0.01" inside the if condition. The function would return x when x2 is close to 0 (smaller than 0.01) which means when x is close to square root of 3. Square root of 3 is 1.732.
Please write comments if you find any of the answers/explanations incorrect, or you want to share more information about the topics discussed above.
- C Language | Set 7
- C Language | Set 1
- C Language | Set 3
- C Language | Set 4
- C Language | Set 9
- C Language | Set 5
- C Language | Set 6
- C Language | Set 8
- C Language | Set 2
- TCS DIGITAL PUZZLE | Lateral Thinking
- Practice questions on Height balanced/AVL Tree
- Practice questions on B and B+ Trees
- Data Structures and Algorithms | Set 37
- Data Structures and Algorithms | Set 36