C-Programming |Gate-2005|
1. What does the following C-statement declare? int
( * f) (int
* ) ;
[GATE – 2005]
a. A function that takes an integer pointer as argument and returns an integer.
b. A function that takes an integer as argument and returns an integer pointer.
c. A pointer to a function that takes an integer pointer as argument and returns an integer.
d. A function that takes an integer pointer as argument and returns a function pointer.
Answer : c)
2. A common property of logic programming languages and functional languages is: [GATE – 2005]
a. both are declarative
b. both are based on λ-calculus
c. both are procedural languages
d. both use Horn-clauses
Answer : a)
3. Which one of the following are essential features of an object-oriented programming language? (GATE CS 2005) (i) Abstraction and encapsulation (ii) Strictly-typedness (iii) Type-safe property coupled with sub-type rule (iv) Polymorphism in the presence of inheritance Answer (b) Abstraction, Encapsulation, Polymorphism and Inheritance are the essential features of a OOP Language (See the Wiki page for OOP). [GATE – 2005]
a. (i) and (ii) only
b. (i) and (iv) only
c. (i), (ii) and (iv) only
d. (i), (iii) and (iv) only
Answer : b)
4. Consider the following C-program:
double foo (double); /* Line 1 */ int main() { double da, db; // input da db = foo(da); } double foo(double a) { return a; } |
The above code compiled without any error or warning. If Line 1 is deleted, the above code will show: [GATE – 2005]
a. no compile warning or error
b. some compiler-warnings not leading to unintended results
c. some compiler-warnings due to type-mismatch eventually leading to unintended results
d. compiler errors
Answer : d)
5. Consider the following C-program:
double foo (double); /* Line 1 */ int main() { double da, db; // input da db = foo(da); } double foo(double a) { return a; } |
The above code compiled without any error or warning. If Line 1 is deleted, the above code will show: [GATE – 2005]
a. 8, 4, 0, 2, 14
b. 8, 4, 0, 2, 0
c. 2, 0, 4, 8, 14
d. 2, 0, 4, 8, 0
Answer : d)
6. The following C function takes two ASCII strings and determines whether one is an anagram of the other. An anagram of a string s is a string obtained by permuting the letters in s.
int anagram (char *a, char *b) {
int count [128], j;
for (j = 0; j < 128; j++) count[j] = 0;
j = 0;
while (a[j] && b[j]) {
A;
B;
}
for (j = 0; j < 128; j++) if (count [j]) return 0;
return 1;
}
Choose the correct alternative for statements A and B. [GATE – 2005]
a. A : count [a[j]]++ and B : count[b[j]]–
b. A : count [a[j]]++and B : count[b[j++]]–
c. A : count [a[j++]]++ and B : count[b[j]]–
d. A : count [a[j]]++ and B : count[b[j]]++
Answer : b)
7. The following C function takes a singly-linked list of integers as a parameter and rearranges the elements of the list. The list is represented as pointer to a structure. The function is called with the list containing the integers 1, 2, 3, 4, 5, 6, 7 in the given order. What will be the contents of the list after the function completes execution? [GATE – 2005]
struct node { int value; struct node *next; ); void rearrange (struct node *list) { struct node *p, *q; int temp; if (!list || !list -> next) return; p = list; q = list -> next; while (q) { temp = p -> value; p -> value = q -> value; q -> value = temp; p = q -> next; q = p ? p -> next : 0; } } |
a. 1, 2, 3, 4, 5, 6, 7
b. 1, 3, 2, 5, 4, 7, 6
c. 2, 1, 4, 3, 6, 5, 7
d. 2, 3, 4, 5, 6, 7, 1
Answer : c)
8. Let a be an array containing n integers in increasing order. The following algorithm determines whether there are two distinct numbers in the array whose difference is a specified number S > 0.
i = 0; j = 1; while (j < n ) { if (E) j++; else if (a[j] - a[i] == S) break; else i++; } if (j < n) printf("yes") else printf ("no"); |
Choose the correct expression for E. [GATE – 2005]
a. a[j] – a[i] > S
b. a[j] – a[i] < S
c. a[i] – a[j] < S
d. a[i] – a[j] > S
Answer : b)
9. Let a and b be two sorted arrays containing n integers each, in non-decreasing order. Let c be a sorted array containing 2n integers obtained by merging the two arrays a and b. Assuming the arrays are indexed starting from 0, consider the following four statements
I. a[i] ≥ b [i] => c[2i] ≥ a [i]
II. a[i] ≥ b [i] => c[2i] ≥ b [i]
III. a[i] ≥ b [i] => c[2i] ≤ a [i]
IV. a[i] ≥ b [i] => c[2i] ≤ b [i]
Which of the following is TRUE? [GATE – 2005]
a. only I and II
b. only I and IV
c. only II and III
d. only III and IV
Answer : c)
C-Programming |Gate-2005|
10. What is the output printed by the following program? [GATE – 2005]
#include<stdio.h> int f(int n, int k) { if (n == 0) return 0; else if (n % 2) return f(n/2, 2*k) + k; else return f(n/2, 2*k) - k; } int main () { printf("%d", f(20, 1)); return 0; } |
a. 5
b. 8
c. 9
d. 20
Answer : c)
C-Programming |Gate-2005|