GATE 2008 Computer Science and Information Technology (CS) Questions with Solutions

GATE 2008

185 questions

MCQ 1851-mark 52 · 2-mark 133

Questions 81–85 of 185

Q81Array and Pointer2 marksMCQ−0.67 if wrong
What is the output printed by the following C code?
 #include <stdio.h>
int main ()
{
    char a [6] = "world";
    int i, j;
    for (i = 0, j = 5; i < j; a [i++] = a [j--]);
    printf ("%s\n", a);
}

Q82Array and Pointer2 marksMCQ−0.67 if wrong
Consider the following C program that attempts to locate an element x in an array Y[] using binary search. The program is erroneous.
 1.   f(int Y[10], int x) {
2.     int i, j, k;
3.     i = 0; j = 9;
4.     do {
5.             k =  (i + j) /2;
6.             if( Y[k] < x)  i = k; else j = k;
7.         } while(Y[k] != x && i < j);
8.     if(Y[k] == x) printf ("x is in the array ") ;
9.     else printf (" x is not in the array ") ;
10. }
The correction needed in the program to make it work properly is

Q83Array and Pointer2 marksMCQ−0.67 if wrong
Consider the following C program that attempts to locate an element x in an array Y[] using binary search. The program is erroneous.
 1.   f(int Y[10], int x) {
2.     int i, j, k;
3.     i = 0; j = 9;
4.     do {
5.             k =  (i + j) /2;
6.             if( Y[k] < x)  i = k; else j = k;
7.         } while(Y[k] != x && i < j);
8.     if(Y[k] == x) printf ("x is in the array ") ;
9.     else printf (" x is not in the array ") ;
10. }
On which of the following contents of Y and x does the program fail?

Q84Array and Pointer2 marksMCQ−0.67 if wrong
Consider the C program below. What does it print?
 #include <stdio.h>
# define swap1 (a, b) tmp = a; a = b; b = tmp
void swap2 ( int a, int b)
{
        int tmp;
        tmp = a; a = b; b = tmp;
 }
void swap3 (int*a, int*b)
{
        int tmp;
        tmp = *a; *a = *b; *b = tmp;
}
int main ()
{
        int num1 = 5, num2 = 4, tmp;
        if (num1 < num2) {swap1 (num1, num2);}
        if (num1 < num2) {swap2 (num1 + 1, num2);}
        if (num1 >= num2) {swap3 (&num1, &num2);}
        printf ("%d, %d", num1, num2);
}

Q85Array and Pointer2 marksMCQ−0.67 if wrong
What is printed by the following C program?
 int f(int x, int *py, int **ppz)			
{						                    	
    int y, z;					                		
    **ppz += 1; z = **ppz;		                
    *py += 2; y = *py;					                	
    x += 3;					                    	
    return x+y+z;
}

void main()
{
    int c, *b, **a;
    c = 4; b = &c; a = &b;
    printf("%d", f(c, b, a));
    	
}