Programming

Question 1

Consider the following C program:

#include <stdio.h>

int counter = 0;

int calc (int a, int b) {
    int c;

    counter++;
    if (b==3) return (a*a*a) ;
    else  {
         c = calc (a, b/3) ;
         return (c*c*c) ;
    }
}

int main ()  {
    calc (4, 81);
    printf ("%d", counter) ;
}

The output of this program is ______.

A
4
B
5
C
6
D
7
       Programming       Programming       GATE 2018
Question 1 Explanation: 
Question 2

Consider the following C program.

#include <stdio.h>
struct Outnode { 
    char x, y, z ; 
};

int main () { 
    struct Ournode p = {'1', '0', 'a'+2} ; 
    struct Ournode *q = &p ; 
    printf ("%c, %c", *((char*)q+1), *((char*)q+2)) ; 
    return 0 ; 
} 

The output of this program is

A
0, c
B
0, a+2
C
‘0’, ‘a+2’
D
‘0’, ‘c’
       Programming       Programming       GATE 2018
Question 2 Explanation: 
char x = ‘a’+2;
The x variable here stores a character ‘c’ in it.
Because +2 will increment ascii value of a from 92 to 95.
Hence the structure p contains 3 character values and they are ‘1’, ‘0’, and ‘c’.
q is a pointer pointing to structure p.
Hence q is pointing to ‘1’, q+1 pointing to ‘0’ and q+2 pointing to ‘c’.
Option d cannot be correct, as though they are characters, printf will not print them in single quotes.
Question 3

Consider the following C program:

#include<stdio.h> 

void fun1(char *s1, char *s2)  { 
     char *tmp;  
     tmp = s1; 
     s1 = s2; 
     s2 = tmp; 
} 

void fun2(char **s2, char **s2)  { 
     char *tmp; 
     tmp = *s1; 
     *s1 = *s2; 
     *s2 = tmp; 
}

int main ()  { 
     char *str1 = "Hi", *str2 = "Bye"; 
     fun1(str1, str2);     printf("%s %s", str1, str2); 
     fun2(&str1, &str2);   printf("%s %s", str1, str2); 
     return 0; 
} 

The output of the program above is

A
Hi Bye Bye Hi
B
Hi Bye Hi Bye
C
Bye Hi Hi Bye
D
Bye Hi Bye Hi
       Programming       Programming       GATE 2018
Question 3 Explanation: 
The first call to the function ‘func1(str1, str2);’ is call by value.
Hence, any change in the formal parameters are NOT reflected in actual parameters.
Hence, str1 points at “hi” and str2 points at “bye”.
The second call to the function ‘func2(&str1, &str2);’ is call by reference.
Hence, any change in formal parameters are reflected in actual parameters.
Hence, str1 now points at “bye” and str2 points at “hi”.
Hence answer is “hi bye bye hi”.
Question 4

Consider the following C code. Assume that unsigned long int type length is 64 bits.

        unsigned long int fun(unsigned long int n)  { 
            unsigned long int i, j, j=0, sum = 0; 
            for (i = n; i > 1; i = i/2) j++; 
            for ( ; j > 1; j = j/2) sum++; 
            return sum; 
        } 

The value returned when we call fun with the input 240 is

A
4
B
5
C
6
D
40
       Programming       Programming       GATE 2018
Question 4 Explanation: 
Since 240 is the input, so first loop will make j = 40.
Next for loop will divide j value (which is 40) by 2, each time until j>1.
j loop starts:
j=40 & sum=1
j=20 & sum=2
j=10 & sum=3
j=5 & sum=4
j=2 & sum=5
j=1 & break
So, sum = 5.
Question 5

Consider the following program written in pseudo-code. Assume that x and y are integers.

Count (x, y)  {
    if (y != 1)  {
        if (x != 1)  {
            print("*") ;
            Count (x/2, y) ;
        }
        else  {
             y = y - 1 ; 
             Count (1024, y) ; 
        }
    }
}

The number of times that the print statement is executed by the call Count(1024, 1024) is ______.

A
10230
B
10231
C
10232
D
10233
       Programming       PRogramming       GATE 2018
Question 5 Explanation: 
#include
int count=0;
Count(x,y){
if(y!=1){
if(x!=1){
printf("*");
count = count +1;
Count(x/2,y);
}
else{
y=y-1;
Count(1024,y);
}
}
}
void main()
{
Count(1024,1024);
printf("\n%d\n",count);
}


Count ( ) is called recursively for every (y = 1023) & for every y, Count ( ) is called (x = 10) times = 1023 × 10 = 10230
Question 6

Consider the following C code:

             #include <stdio.h>
             int *assignval(int *x, int val)   {
                  *x = val;
                  return x;
             }

             void main ( )  {
                  int  *x = malloc(sizeof(int));
                  if(NULL == x)  return;
                     x = assignval(x, 0);
                     if(x)  {
                           x = (int *)malloc(size of(int));
                           if(NULL == x)  return;
                              x = assignval(x, 10);
                     }
                     printf("%dn",  *x);
                     free(x);
              }

The code suffers from which one of the following problems:

A
compiler error as the return of malloc is not typecast approximately
B
compiler error because the comparison should be made as x==NULL and not as shown
C
compiles successfully but execution may result in dangling pointer
D
compiles successfully but execution may result in memory leak
       Programming       Programming       GATE 2017 [Set-1]
Question 6 Explanation: 
Option A:
In C++, we need to perform type casting, but in C Implicit type casting is done automatically, so there is no compile time error, it prints10 as output.
Option B:
NULL means address 0, if (a == 0) or (0 == a) no problem, though we can neglect this, as it prints 10.
Option C:
x points to a valid memory location. Dangling Pointer means if it points to a memory location which is freed/ deleted.
int*ptr = (int*)malloc(sizeof(int));
free(ptr); //ptr becomes a dangling pointer
ptr = NULL; //Removing Dangling pointers condition
Option D:
x is assigned to some memory location
int*x = malloc(sizeof(int));
→ (int*)malloc(sizeof(int)) again assigns some other location to x, previous memory location is lost because no new reference to that location, resulting in Memory Leak.
Hence, Option D.
Question 7

Consider the following two functions.

void fun1(int n)   {                 void fun2(int n)   {
        if(n == 0)  return;                  if(n == 0)  return;
        printf("%d", n);                     printf("%d", n);
        fun2(n - 2);                         fun1(++n);
        printf("%d", n);                     printf("%d", n);
}                                    }

The output printed when fun1(5) is called is

A
53423122233445
B
53423120112233
C
53423122132435
D
53423120213243
       Programming       Programming       GATE 2017 [Set-1]
Question 7 Explanation: 


In fun2, we increment (pre) the value of n, but in fun1, we are not modifying the value.
Hence increment in value in recursion (back).
Hence, 5 3 4 2 3 1 2 2 2 3 3 4 4 5.
Question 8

Consider the C functions foo and bar given below:

         int foo(int val)   {
                 int x = 0;
                 while (val>0)   {
                    x = x + foo(val--); 
                 }
                 return val;
               }

               int bar(int val)   {
                  int x = 0;
                  while (val>0)   {
                      x = x + bar(val-1);
                  }
                  return val;
               }

Invocations of foo(3) and bar(3) will result in:

A
Return of 6 and 6 respectively.
B
Infinite loop and abnormal termination respectively.
C
Abnormal termination and infinite loop respectively.
D
Both terminating abnormally.
       Programming       Programming       GATE 2017 [Set-1]
Question 8 Explanation: 
while(val>0)
{
x = x + foo(val--);
}
In this case foo(val--) is same as foo(val) & val-- ;
Because the recursive function call is made without changing the passing argument and there is no Base condition which can stop it.
It goes on calling with the same value ‘val’ & the system will run out of memory and hits the segmentation fault or will be terminated abnormally.
The loop will not make any difference here.
while(val>0)
{
x = x + bar(val-1);
}
bar(3) calls bar(2)
bar(2) calls bar(1)
bar(1) calls bar(0) ⇾ Here bar(0) will return 0.
bar(1) calls bar(0)
bar(1) calls bar(0)……..
This will continue.
Here is a problem of infinite loop but not abrupt termination.
Some compilers will forcefully preempt the execution.
Question 9

Consider the following C program.

#include <stdio.h>
#include <string.h>

void printlength (char*s, char*t)   {
   unsigned int c = 0;
   int len = ((strlen(s) - strlen(t)) > c) ? strlen(s):strlen(t);
   printf("%d\n", len);
}

void main ()  { 
   char*x = "abc";
   char*y = "defgh";
   printlength(x,y);
}

Recall that strlen is defined in string.h as returning a value of type size_t, which is an unsigned int. The output of the program is _________.

A
3
B
4
C
5
D
6
       Programming       Programming       GATE 2017 [Set-1]
Question 9 Explanation: 
main ( )
{
char*x = "abc";
char*y = "defgh";
printlength(x,y);
}
printlength(char*3, char*t)
{
unsigned int c = 0;
int len = ((strlen(s) - strlen(t))> c) ? strlen(s) : strlen(t);
printf("%d", len);
}
Here strlen(s) - strlen(t) = 3 - 5 = -2
But in C programming, when we do operations with two unsigned integers, result is also unsigned. (strlen returns size_t which is unsigned in most of the systems).
So this result '-2' is treated as unsigned and its value is INT_MAX-2.
Now the comparison is in between large number & another unsigned number c, which is 0.
So the comparison returns TRUE here.
Hence (strlen(s) - strlen(t))>0 will return TRUE, on executing, the conditional operator will return strlen(s)
⇒ strlen(abc) = 3
Question 10

The output of executing the following C program is __________.

           #include<stdio.h>
           int total (int v)   {
               static int count=0;
               while(v)   {
                   count += v&1;
                   v ≫= 1;
               }     
               return count;
           }

           void main()    {
               static int x = 0;
               int i = 5;
               for(; 1> 0; i--)    {
                  x = x + total(i);
               }
               printf("%d\n", x);
           }
A
23
B
24
C
25
D
26
       Programming       Programming       GATE 2017 [Set-1]
Question 10 Explanation: 
Arithmetic operators have least priority in this case, as count+=v & 1, we first compute v& 1 and then adds to count variable.

Question 11

Match the following:

 
A
P→(ii), Q→(iv), R→(i), S→(iii)
B
P→(ii), Q→(i), R→(iv), S→(iii)
C
P→(ii), Q→(iv), R→(iii), S→(i)
D
P→(iii), Q→(iv), R→(i), S→(ii)
       Programming       Match-the-Following       GATE 2017 [Set-2]
Question 11 Explanation: 
Static char var:
⇾ A variable located in Data Section of memory

P→(ii), Q→(iv), R→(i), S→(iii)
Question 12

Consider the following function implemented in C:

void printxy (int x, int y)   {
      int *ptr;
      x = 0;
      ptr = &x;
      y = *ptr;
      *ptr = 1;
      printf("%d,%d",x,y);
}

The output of invoking printxy(1, 1) is

A
0, 0
B
0, 1
C
1, 0
D
1, 1
       Programming       Programming       GATE 2017 [Set-2]
Question 12 Explanation: 
printxy (int x, int y)
{
int *ptr;
x = 0;
ptr = &x;
y = *ptr;
*ptr = 1;

}
printxy (1, 1)
Question 13

Consider the C program fragment below which is meant to divide x and y using repeated subtractions. The variables x, y, q and r are all unsigned int.

          while (r >= y)  {
              r = r - y;
              q = q + 1;
          }

Which of the following conditions on the variables x, y, q and r before the execution of the fragment will ensure that the loop terminates in a state satisfying the condition x == (y*q + r)?

A
(q == r) && (r == 0)
B
(x > 0) && (r == x) && (y > 0)
C
(q == 0) && (r == x) && (y > 0)
D
(q == 0) && (y > 0)
       Programming       Programming       GATE 2017 [Set-2]
Question 13 Explanation: 
Divide x by y.
x, y, q, r are unsigned integers.
while (r >= y)
{
r = r – y;
q = q + 1;
}
Loop terminates in a state satisfying the condition
x == (y * q + r)
y ⇒ Dividend = Divisor * Quotient + Remainder
So, to divide a number with repeated subtractions, the Quotient should be initialized to 0 and it must be incremented for every subtraction.
So initially q=0 which represents
x = 0 + r ⇒ x = r
and y must be a positive value (>0).
Question 14

Consider the following snippet of a C program. Assume that swap(&x, &y)  exchanges the contents of x and y.

int main ()  {
      int array[] = {3, 5, 1, 4, 6, 2};
      int done = 0;
      int i;

      while (done == 0)  {
           done = 1;
           for (i=0; i<=4; i++)  {
                if (array[i] < array[i+1])  {
                       swap (&array[i], &array[i+1]);
                       done = 0;
                }
           }
           for (i=5; i>=1; i--)  {
                if (array[i] > array[i-1])   {
                      swap(&array[i], &array[i-1]);
                      done=0;
                }
           }
       }
       printf("%d", array[3]);
}

The output of the program is ___________.

A
3
B
4
C
5
D
6
       Programming       Programming       GATE 2017 [Set-2]
Question 14 Explanation: 
Swap (&x, &y) exchanges the contents of x & y.

(1) ⇒ 1st for i = 0 <= 4
a[0] < a[1] ≃ 3<5 so perform swapping
done =

(1) ⇒ no swap (3, 1)
(2) ⇾ perform swap (1, 4)

(1) ⇒ perform swap (1, 6)

(1) ⇒ perform swap (1, 2)

(1) ⇒ (done is still 0)
for i = 5 >= 1 a[5] > a[4] ≃ 1>2 – false. So, no swapping to be done
(2) ⇾ no swap (6, 2)
(3) ⇾ swap (4, 6)

(1) ⇒ Swap (3, 6)

(1) ⇒ Swap (5, 6)

⇒ Done is still 0. So while loop executes again.
(1) ⇾ no swap (6, 5)
done = 1
(2) ⇾ No swap (5, 3)
(3) ⇾Swap (3, 4)

So, array [3] = 3
Question 15

Consider the following C program:

#include <stdio.h>
int main()
{
    int m = 10;
    int n, n1;
    n = ++m;
    n1 = m++;
    n--;
    --n1;
    n -= n1;
    printf("%d",n);
    return 0;
}

The output of the program is _______.

A
0
B
1
C
2
D
3
       Programming       Programming       GATE 2017 [Set-2]
Question 15 Explanation: 
Question 16

Consider the following C program.

#include<stdio.h>
#include<string.h>
int main ()  {
  char* c = "GATECSIT2017";
  char* p = c;
  printf("%d", (int) strlen (c + 2[p] - 6[p] - 1));
  return 0;
}

The output of the program is __________.

A
1
B
2
C
4
D
6
       Programming       Programming       GATE 2017 [Set-2]
Question 16 Explanation: 
char * C = “GATECSIT2017”;
char * P = C;
(int) strlen (C + 2[P] – 6[P] – 1)

C + 2[P] - 6[P] – 1
     ∵2[P] ≃ P[2]
100 + P[2] – P[6] – 1
100 + T – I – 1
100 + 84 – 73 – 1
     ASCII values: T – 84, I – 73
100 + 11 – 1
= 110
(int) strlen (110)
strlen (17) ≃ 2
Question 17

Consider the following C program.

void f(int, short);
void main ()
{
     int i = 100;
     short s = 12;
     short *p = &s;
     __________ ;         // call to f()
}

Which one of the following expressions, when placed in the blank above, will NOT result in a type checking error?

A
f(s, *s)
B
i = f(i, s)
C
f(i, *s)
D
f(i, *p)
       Programming       Programming       GATE 2016 [Set-1]
Question 17 Explanation: 
int i = 100;
short s = 12;
short *p = &s;
_______ // call to f ( ) :: (void f(int,short);)
It is clearly mentioned the return type of f is void.
By doing option elimination
(A) & (C) can be eliminated as s is short variable and not a pointer variable.
(B) i = f(i, s) is false because f’s return type is void, but here shown as int.
(D) f(i, *p)
i = 100
*p = 12
Hence TRUE
Question 18

Consider the following C program.

#include<stdio.h>
void mystery(int *ptra, int *ptrb) {
      int *temp;
      temp = ptrb;
      ptrb = ptra;
      ptra = temp;
}
int main() {
      int a=2016, b=0, c=4, d=42;
      mystery(&a, &b);
      if (a < c)
             mystery(&c, &a);
      mystery(&a, &d);
      printf("%d\n", a);
}

The output of the program is ________.

A
2016
B
2017
C
2018
D
2019
       Programming       Programming       GATE 2016 [Set-1]
Question 18 Explanation: 

For the first mystery (&a, &b);

temp = ptr b
ptr b = ptr a
ptr a = temp
If (a The function mystery (int *ptra, int *ptrb) does not change the value of variables pointed by pointers, instead it only changes the addresses inside the pointers, which is in no way going to modify the values of a, b, c, d.
Hence, a = 2016 will be printed.
Question 19

The following function computes the maximum value contained in an integer array p[] of size n (n >= 1).

       int max(int *p, int n) {
           int a=0, b=n-1;
           
           while (__________) {
               if (p[a] <= p[b]) {a = a+1;}
               else                 {b = b-1;}
           }

           return p[a];
       }

The missing loop condition is

A
a != n
B
b != 0
C
b > (a + 1)
D
b != a
       Programming       Programming       GATE 2016 [Set-1]
Question 19 Explanation: 
main ( )
{
int arr [ ] = {3, 2, 1, 5, 4};
int n = sizeof(arr) / sizeof (arr[0]);
printf (max(arr, 5));
}
int max (int *p, int n)
{
int a = 0, b = n – 1;
(while (a!=b))
{
if (p[a] <= p[b])
{
a = a + 1;
}
else
{
b =b – 1;
}
}
return p[a];
}
The function computes the maximum value contained in an integer array p[ ] of size n (n >= 1).
If a = = b, means both are at same location & comparison ends.
Question 20

What will be the output of the following C program?

void count(int n)  {
     static int d=1;

     printf("%d ", n);
     printf("%d ", d);
     d++;
     if(n>1) count(n-1);
     printf("%d ", d);
}

void main() {
     count(3);
}
A
3 1 2 2 1 3 4 4 4
B
3 1 2 1 1 1 2 2 2
C
3 1 2 2 1 3 4
D
3 1 2 1 1 1 2
       Programming       Programming       GATE 2016 [Set-1]
Question 20 Explanation: 

Count (3)
static int d = 1
It prints 3, 1
d++; //d = 2
n>1, count(2)
prints 2, 2
d++; // d = 3
n>1, count(1)
prints 1, 3 → Here n = 1, so condition failed & printf (last statement) executes thrice & prints d
d++; //d=4 value as 4. For three function calls, static value retains.
∴ 312213444
Question 21

What will be the output of the following pseudo-code when parameters are passed by reference and dynamic scoping is assumed?

       a=3;
       void n(x) {x = x * a; print(x);}
       void m(y) {a = 1; a = y - a; n(a); print(a);}
       void main() {m(a);}
A
6, 2
B
6, 6
C
4, 2
D
4, 4
       Programming       Programming       GATE 2016 [Set-1]
Question 21 Explanation: 

First m(a) is implemented, as there are no local variables in main ( ), it takes global a = 3;
m(3) is passed to m(y).
a = 1
a = 3 – 1 = 2
n(2) is passed to n(x).
Since it is dynamic scoping
x = 2 * 2 = 4 (a takes the value of its calling function not the global one).
The local x is now replaced in m(y) also.
Hence, it prints 4,4.
And we know it prints 6, 2 if static scoping is used.
It is by default in C programming.
Question 22

The value printed by the following program is __________.

     void f(int* p, int m) {
        m = m + 5;
        *p = *p + m;
        return;
     }

     void main() {
        int i=5, j=10;
        f(&i, j);
        printf("%d", i+j);
     }
A
30
B
31
C
32
D
33
       Programming       Programming       GATE 2016 [Set-2]
Question 22 Explanation: 

P is a pointer stores the address of i, & m is the formal parameter of j.
Now, m = m + 5;
*p = *p + m;

Hence, i + j will be 20 + 10 = 30.
Question 23

The following function computes XY for positive integers X and Y.

       int exp (int X, int Y) {
           int res = 1, a = X, b = Y;

           while ( b != 0 ){
               if ( b%2 == 0) { a = a*a; b = b/2; }
               else           { res = res*a; b = b-1; }
           }
           return res;

        }

Which one of the following conditions is TRUE before every iteration of the loop?

A
XY = ab
B
(res * a)Y = (res * X)b
C
XY = res * ab
D
XY = (res * a)b
       Programming       Programming       GATE 2016 [Set-2]
Question 23 Explanation: 
int exp (int X, int Y)
{
int res = 1, a = X, b = Y;
while (b != 0)
{
if (b%2 == 0)
{
a = a*a;
b = b/2;
}
else
{
res = res*a;
b = b – 1;
}
}
return res;
}
From that explanation part you can understand the exponent operation, but to check the conditions, first while iteration is enough.
x = 2, y = 3, res = 2, a = 2, b = 2.
Only (C) satisfies these values.
xy = res * ab
23 = 2 * 22 = 8
Explanation:
Will compute for smaller values.
Let X = 2, Y = 3, res = 1
while (3 != 0)
{
if(3%2 == 0) - False
else
{
res = 1*2 = 2;
b = 3 – 1 = 2;
}
For options elimination, consider
return res = 2 (but it is out of while loop so repeat while)
__________
while (2 != 0)
{
if (2%2 == 0) - True
{
a = 2*2 = 4
b = 2/2 = 1
}
__________
repeat while
while (1 != 0)
{
if (1%2 == 0) - False
else
{
res = 2 * 4 = 8
b = 1 – 1 = 0
}
__________
while (0 != 0) - False
return res = 8 (23)
Question 24

Consider the following program:

    int f(int *p, int n)
    {
       if (n <= 1) return 0;
       else return max (f(p+1,n-1),p[0]-p[1]);
    }

    int main()
    {
       int a[] = {3,5,2,6,4};
       printf("%d", f(a,5));
    }
Note: max(x,y) returns the maximum of x and y.

The value printed by this program is __________.

A
3
B
4
C
5
D
6
       Programming       Programming       GATE 2016 [Set-2]
Question 24 Explanation: 
Given

f(a, 5) ⇒ f(100, 5)
Question 25

The output of the following C program is __________.

void f1 (int a, int b)
{
  int c;
  c=a; a=b; b=c;
}
void f2 (int *a, int *b)
{
  int c;
  c=*a; *a=*b;*b=c;
}
int main()
{
  int a=4, b=5, c=6;
  f1(a, b);
  f2(&b, &c);
  printf (“%d”, c-a-b);
  return 0;
}
A
-5
B
6
C
7
D
8
       Programming       Programming       GATE 2015 [Set-1]
Question 25 Explanation: 
Function f1 will not swap the value of 'a' and 'b' because f1 is call by value.
But f2 will swap the value of 'b' and 'c' because f2 is call by reference. So finally the value of
a=4
b=6
c=5
So, answer will be
c - a - b
5 - 4 - 6 = -5
Question 26

What is the output of the following C code? Assume that the address of x is 2000 (in decimal) and an integer requires four bytes of memory.

 
int main() { 
        unsigned int x[4][3] = 
          {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}};
        printf("%u, %u, %u", x+3, *(x+3), *(x+2)+3);
}
A
2036, 2036, 2036
B
2012, 4, 2204
C
2036, 10, 10
D
2012, 4, 6
       Programming       Programming       GATE 2015 [Set-1]
Question 26 Explanation: 
⇒ Address of x = 2000
⇒ x [4] [3] can represents that x is a 2-dimensional array.
⇒ x+3 = (Address of x) + 3 * 4 * 3 [3×4×3 is inner dimention]
= 2000 + 36
= 2036
⇒ *(x+3) also returns the address i.e., 2036.
The '*' represents 1 - D but x is starting at 2036.
⇒ *(x+3)+3 = *(Address of x + 2 * 3 * 4) + 3
= *(2000 + 24) +3
= *(2024) + 3 ['*' will change from 2D to 1D]
= 2024 + 3 * 4
= 2024 + 12
= 2036
Question 27

Consider the following pseudo code, where x and y are positive integers.

begin
   q := 0
   r := x
while r >= y do
   begin
      r := r – y
      q := q + 1
   end
end

The post condition that needs to be satisfied after the program terminates is

A
{r = qx+y ∧ r
B
{x = qy+r ∧ r
C
{y = qx+r ∧ 0
D
{q+10}
       Programming       Programming       GATE 2015 [Set-1]
Question 27 Explanation: 
The loop terminates when r In each iteration q is incremented by 1 and y is subtracted from 'r'. Initial value of 'r' is 'x'. So, loop iterates x/y times and q will be equal to x/y and r = x%y.
⇒ x = qy + r
Question 28

Consider the following C program segment.

while (first <= last)
{
   if (array [middle] < search)
      first = middle +1;
   else if (array [middle] == search)
      found = True;
   else last = middle – 1;
   middle = (first + last)/2;
}
if (first < last) not Present = True;

The cyclomatic complexity of the program segment is __________.

A
5
B
6
C
7
D
8
       Programming       Programming       GATE 2015 [Set-1]
Question 28 Explanation: 
Note: Out of syllabus.
Question 29

Consider the following C function.

int fun1 (int n)
{
   int i, j, k, p, q = 0;
   for (i = 1; i<n; ++i)
   {
      p = 0;
      for (j = n; j > 1; j = j/2)
         ++p;
      for (k = 1; k < p; k = k*2)
         ++q;
   }
   return q;
}

Which one of the following most closely approximates the return value of the function fun1?

A
n3
B
n(log n)2
C
nlog n
D
nlog (log n)
       Programming       Programming       GATE 2015 [Set-1]
Question 29 Explanation: 
for (i=1; i p=0;
for (j=n; j>1; j=j/2) --- p = O(log n) ++p;
for (k=1; k ++q;
}
∴ The return value of the function fun1,
q = n log p
= n log log n
Question 30

Consider the following function written the C programming language.

       void foo(char *a) {
          if(*a && *a != ' ') {
              foo(a+1);
              putchar(*a);
           }
       }

The output of the above function on input "ABCD EFGH" is

A
ABCD EFGH
B
ABCD
C
HGFE DCBA
D
DCBA
       Programming       Programming       GATE 2015 [Set-2]
Question 30 Explanation: 

if condition fails
& returns controls
∴ DCBA will be pointed
Question 31

Consider the following C functions

      int fun(int n) {
          int x = 1, k;
          if(n == 1) return x;
          for(k = 1; k < n; ++k)
              x = x + fun(k) * fun(n - k);
          return x;
      }

The return value of fun(5) is _______.

A
51
B
52
C
53
D
54
       Programming       Programming       GATE 2015 [Set-2]
Question 31 Explanation: 
Recurrence Relation is
f(n) = 1; if n = 1
Question 32

Consider the C program below.

#include 
int *A, stkTop;
int stkFunc (int opcode, int val)
{
    static int size=0, stkTop=0;
    switch (opcode)
    {
    case -1:
        size = val;
        break;
    case 0:
        if (stkTop < size ) A[stkTop++]=val;
        break;
    default:
        if (stkTop) return A[--stkTop];
    }
    return -1;
}
int main()
{
    int B[20];
    A=B;
    stkTop = -1;
    stkFunc (-1, 10);
    stkFunc (0, 5);
    stkFunc (0, 10);
    printf ("%dn", stkFunc(1, 0)+ stkFunc(1, 0));
}

The value printed by the above program is ___________

A
-2
B
2
C
-1
D
15
       Programming       Programming       GATE 2015 [Set-2]
Question 32 Explanation: 
When first time stkFunc (-1,10) will be called then, inside Switch(opcode) the control will go to Case-I, where size = 10.
When next time stkFunc (0,5) is called then, inside Switch(opcode), the control will go to Case-0, where A[0] = 5 and stkTop = 0+1 = 1.
When next time stkFunc (0,10) is called then, inside Switch (opcode), the control will go to Case '0', where A[1] = 10 and stkTop = 1+1 = 2.
When next time stkFunc(1,0) is called from inside the printf statement, then inside Switch(opcode), the control will go to default and stkTop = 2-1 = 1 and value of A[1] will get returned, i.e., 10.
When next time stkFunc(1,0) is called from inside the printf statement, then inside Switch(opcode), the control will go to default and stkTop = 1-1 = 0 and value of A[0] will get returned, i.e., 5.
Finally the two values 10 & 5 will be added and printed.
Question 33

Consider the following C program segment.

# include 
int main( )
{
    char s1[7] = "1234", *p;
    p = s1 + 2;
    *p = '0' ;
    printf ("%s", s1);
} 

What will be printed by the program?

A
12
B
120400
C
1204
D
1034
       Programming       Programming       GATE 2015 [Set-3]
Question 33 Explanation: 
p = s1+2;
p now points to third element in s1, i.e., '3'.
*p = '0', will make value of '3' as '0' in s1. And finally s1 will become 1204.
Question 34

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
       Programming       Programming       GATE 2015 [Set-3]
Question 34 Explanation: 
Question 35

Consider the following C program.

# include 
int main( )
{
  static int a[] = {10, 20, 30, 40, 50};
  static int *p[] = {a, a+3, a+4, a+1, a+2};
  int **ptr = p;
  ptr++;
  printf("%d%d", ptr - p, **ptr};
}

The output of the program is _________.

A
140
B
150
C
160
D
170
       Programming       Programming       GATE 2015 [Set-3]
Question 35 Explanation: 

**ptr = 40
∴ printf (“%d%d”, p + r – p, p + r) will print 140.
Question 36

Consider the following C program:

# include 
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
10
B
11
C
12
D
13
       Programming       Programming       GATE 2015 [Set-3]
Question 36 Explanation: 
j = 2*3 / 4+2.0 / 5+8 / 5;
= 6 / 4+2.0 / 5+1;
= 1 + 0.4 + 1
= 2.4
But since j is integer,
j=2
Now,
k = k - (--j)
k = 0 - (1) = -1
When i=0, i+k = -1,
printf executed 1 time
When i=1, i+k = 0,
printf executed 1 time
When i=2, i+k = 1,
printf executed 3 times
When i=3, i+k = 2,
printf executed 3 times
When i=4, i+k = 3,
printf executed 2 times
∴ Total no. of times printf executed is,
1 + 1 + 3 + 3 + 2 = 10
Question 37

Consider the following C program. The output of the program is __________.

# include 
int f1(void);
int f2(void);
int f3(void);
int x = 10;
int main()
{
    int x = 1;
    x += f1() + f2() + f3() + f2();
    pirntf("%d", x);
    return 0;
}
 
int f1()
{
    int x = 25;
    x++;
    return x;
}
 
int f2( )
{
    static int x = 50;
    x++;
    return x;
}
 
int f3( )
{
    x *= 10;
    return x;
}
A
230
B
240
C
250
D
260
       Programming       Programming       GATE 2015 [Set-3]
Question 37 Explanation: 
x = x + f1( ) + f2( ) + f3( ) + f4( )
f1( ) = 25 + 1 = 26
f2( ) = 50 + 1 = 51
f3( ) = 10 × 10 = 100
f2( ) = 51 × 1 = 52 (Since here x is static variable so old value retains)
∴ x = 1+26+51+100+52 = 230
Question 38

Consider the following program in C language:

#include 
main()
{
    int i;
    int *pi = &i;
    scanf("%d", pi);
    printf("%dn", i+5);
}

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.
       Programming       Programming       GATE 2014 [Set-1]
Question 38 Explanation: 
int i; // Initially i takes the Garbage value
int *pi = &i; // pi is a pointer which stores the address of i.
scanf (pi); // pi = &i (we rewrite the garbage value with our values) say x = 2
printf (i+5); // i+5 = x+5 = 2+5 = 7
Hence on execution, the value printed is 5 more than the integer value entered.
Question 39

Consider the function func shown below:

int func(int num)
{
    int count = 0;
    while (num)
    {
        count++;
        num >>= 1;
    }
    return (count);
}

The value returned by func(435)is __________.

A
9
B
10
C
11
D
12
       Programming       Programming       GATE 2014 [Set-2]
Question 39 Explanation: 
Shift right of 1, which means the number gets half.
Shift left of 1, which means the number gets doubled.
In program, shift right of 1 is given, means every time we enter the loop the number will get halved, and the value of count will get incremented by 1. And when the value of num will become zero then the while loop will get terminated. So,
num = 435/2 = 217/2 = 108/2 = 54/2 = 27/2= 13/2 = 6/2 = 3/2 = 1/2 = 0
Count = 9
So, the value count that will get returned is 9.
Question 40

Suppose n and p are unsigned int variables in a C program. We wish to set p to nC3. If n is large, which one of the following statements is most likely to set p  correctly?

A
p = n * (n-1) * (n-2) / 6;
B
p = n * (n-1) / 2 * (n-2) / 3;
C
p = n * (n-1) / 3 * (n-2) / 2;
D
p = n * (n-1) * (n-2) / 6.0;
       Programming       Programming       GATE 2014 [Set-2]
Question 40 Explanation: 
n & p are unsigned int variable.
From the options n*(n-1)*(n-2) will go out of range. So eliminate A & D.
n*(n-1) is always an even number. So subexpression n(n-1)/2 also an even number.
n*(n-1)/ 2*(n-2), gives a number which is a multiple of 3. So dividing with 3 will not have any loss. Hence B is option.
Question 41

Consider the following function

double f(double x){
  if (abs(x*x - 3) < 0.01) return x;
  else return f(x/2 + 1.5/x);
}

Give a value q (to 2 decimals) such that f(q) will return q:_____.

A
1.73
B
1.74
C
1.75
D
1.76
       Programming       Programming       GATE 2014 [Set-2]
Question 41 Explanation: 
f(q) will return q, if
x2 - 3 < 0.01 will become True.
So, x2 - 3 < 0.01
x2 - 3 < 0.01
x2 < 3.01
x < 1.732
Hence, x = 1.73.
Question 42

Consider the C function given below.

int f(int j)
{
  static int i = 50;
  int k;
  if (i == j)
  {
    printf(“something”);
    k = f(i);
    return 0;
  }
  else return 0;
}

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.
       Programming       Programming       GATE 2014 [Set-2]
Question 42 Explanation: 
Let's say that value of j given inside the function is 50.
int f(int j)
{
static int i = 50;
int k;
if (i == j) // This will be True.
{
printf ("Something");
k = f(i); // Again called f(i) with value of i as 50. So, the function will run into infinite loop.
return 0;
}
else return 0;
}
Question 43

Let A be a square matrix of size n x n. Consider the following program. What is the expected output?

C = 100
for i = 1 to n do
    for j = 1 to n do
    {
        Temp = A[i][j] + C
        A[i][j] = A[j][i]
        A[j][i] = Temp - C
    } 
for i = 1 to n do
    for j = 1 to n do
        Output(A[i][j]);
A
The matrix A itself
B
Transpose of the matrix A
C
Adding 100 to the upper diagonal elements and subtracting 100 from lower diagonal elements of A
D
None of the above
       Programming       Programming       GATE 2014 [Set-3]
Question 43 Explanation: 
Let be a small matrix.
For first row iteration, it get swapped and becomes
For second row iteration, it comes to the original position
=A
So, it is the same matrix A.
Question 44

The minimum number of arithmetic operations required to evaluate the polynomial P(X) = X5 + 4X3 + 6X + 5 for a given value of X, using only one temporary variable is ________.

A
7
B
8
C
9
D
10
       Programming       Arithmetic-Expressions       GATE 2014 [Set-3]
Question 44 Explanation: 
The minimum number of arithmetic operations required to evaluate
P(X) = x5+4x3+6x+5
= x(x4+4x2+6)+5
= x(x(x3+4x)+6)+5
= x(x(x(x2+4))+6)+5
= x(x(x(x(x)+4))+6)+5
4 multiplications & 3 additions.
4 + 3 = 7
Question 45

Consider the following function:

int unknown(int n) {
    int i, j, k = 0;
    for (i  = n/2; i <= n; i++)
        for (j = 2; j <= n; j = j * 2)
            k = k + n/2;
    return k;
 }
A
Θ(n2)
B
Θ(n2 log n)
C
Θ(n3)
D
Θ(n3 logn)
       Programming       Programming       GATE 2013
Question 45 Explanation: 
Outer loop runs for (n/2) times and inner loop runs for (logn) times.
So, the total number of times loop runs is (n/2 logn).
So, the final k value will be n/2*(n/2 logn) = O(n2logn)
= (n/2+1).n/2 ∙log n
= (n2log n)
Question 46

Consider the following languages.

    L1 = {0p1q0r|p,q,r≥0}
    L2 = {0p1q0r|p,q,r≥0, p≠r}

Which one of the following statements is FALSE?

A
L2 is context-free.
B
L1∩ L2 is context-free.
C
Complement of L2 is recursive.
D
Complement of L1 is context-free but not regular.
       Programming       CFL&PDA       GATE 2013
Question 46 Explanation: 
L1 = 0*1*0* which is regular language and in L2 we have one comparison (i.e. p ≠ r) so it is CFL.
Intersection of a regular language with a context free language is context free language (by closure properties of regular language) So L1∩ L2 is context-free.
L2 is CFL and CFL is not closed under complementation so we have to assume L2 as CSL (since every CFL is CSL) and CSL is closed under complement so Complement of L2 must be CSL and every CSL is recursive so Complement of L2 is recursive.
Since L1 is regular and regular language is closed under complement so complement of L1 must be regular and hence the statement Complement of L1 is context-free but not regular is a false statement.
Question 47

The procedure given below is required to find and replace certain characters inside an input character string supplied in array A. The characters to be replaced are supplied in array oldc, while their respective replacement characters are supplied in array newc. Array A has a fixed length of five characters, while arrays oldc and newc contain three characters each. However, the procedure is flawed

void find_and_replace(char *A, char *oldc, char *newc) {
    for (int i = 0; i < 5; i++)
       for (int j = 0; j < 3; j++)
           if (A[i] == oldc[j]) A[i] = newc[j];
}

The procedure is tested with the following four test cases

(1) oldc = "abc", newc = "dab" 
(2) oldc = "cde", newc = "bcd" 
(3) oldc = "bca", newc = "cda" 
(4) oldc = "abc", newc = "bac" 

If array A is made to hold the string “abcde”, which of the above four sest cases will be successful in exposing the flaw in this procedure?

A
None
B
2 only
C
3 and 4 only
D
4 only
       Programming       Programming       GATE 2013
Question 47 Explanation: 
The test cases 3 & 4 captures the flaw. The code does not works fine when an old character is replaced by a new character & new character is again replaced by another new character.
1, 2 works fine, 3, 4 carries flaw.
Question 48

What will be the output of the following C program segment?

char inchar = 'A';
switch (inchar)
{
case 'A' :
    printf ("choice A n") ;
case 'B' :
    printf ("choice B ") ;
case 'C' :
case 'D' :
case 'E' :
default:
    printf ("No Choice") ;
}
A
No Choice
B
Choice A
C
D
Program gives no output as it is erroneous
       Programming       C-Programming       GATE 2012
Question 48 Explanation: 
Everything in the switch will be executed, because there is no break; statement after case ‘A’. So it executes all the subsequent statements until it find a break;
So,
→ Choice A
→ Choice B. No choice. Is the output.
Question 49

Consider the following C program

int a, b, c = 0;
void prtFun (void);
int main ()
{
    static int a = 1; /* line 1 */
    prtFun();
    a += 1;
    prtFun();
    printf ( "n %d %d " , a, b) ;
}
  
void prtFun (void)
{
    static int a = 2; /* line 2 */
    int b = 1;
    a += ++b;
    printf (" n %d %d " , a, b);
}

What output will be generated by the given code segment?

A
B
C
D
       Programming       C-Programming       GATE 2012
Question 49 Explanation: 

Hence
4 2
6 2
2 0
Question 50

Consider the following C program

int a, b, c = 0;
void prtFun (void);
int main ()
{
    static int a = 1; /* line 1 */
    prtFun();
    a += 1;
    prtFun();
    printf ( "n %d %d " , a, b) ;
}
  
void prtFun (void)
{
    static int a = 2; /* line 2 */
    int b = 1;
    a += ++b;
    printf (" n %d %d " , a, b);
}

What output will be generated by the given code segment if:

    Line 1 is replaced by auto int a = 1;
    Line 2 is replaced by register int a = 2;
A
B
C
D
       Programming       C-Programming       GATE 2012
Question 50 Explanation: 
Line 1 replaced by auto int a=1;
Line 2 replaced by register int a=2;
In main there will be no change if it is static or auto because of a+=1 the auto variable a is updated to 2 from 1.
In prtfun ( ), register makes a difference.
For first print statement a is updated to 4 & prints 4, 2.
But now it is not a static variable to retain the value of a to 4. So it becomes 2, when second function call takes place & prints 4, 2 again. There is no change in b, it acts like a local variable.
Hence,
4 2
4 2
2 0.
Question 51

What does the following fragment of C-program print?

char c[] = "GATE2011";
char *p =c;
printf("%s", p + p[3] - p[1]) ; 
A
GATE2011
B
E2011
C
2011
D
011
       Programming       C-Programming       GATE 2011
Question 51 Explanation: 
p is the starting address of array.
p[3] - p[1] = 4, and p+4 will be pointing to the fifth position in the array 'c'. So printf starts printing from 2 and prints 2011.
Question 52

Consider the following recursive C function that takes two arguments.

unsigned int foo(unsigned int n, unsigned int r)  {
       if(n>0) return ((n%r) + foo(n/r,r));
       else return 0;
}

What is the return value of the function foo when it is called as foo(513,2)?

A
9
B
8
C
5
D
2
       Programming       C-Programming       GATE 2011
Question 52 Explanation: 

∴ 1+0+0+0+0+0+0+0+0+1+0 = 2
Question 53

Consider the following recursive C function that takes two arguments

unsigned int foo(unsigned int n, unsigned int r) {
  if (n  > 0) return (n%r +  foo (n/r, r ));
  else return 0;
}

What is the return value of the function foo when it is called as foo(345, 10) ?

A
345
B
12
C
5
D
3
       Programming       C-Programming       GATE 2011
Question 53 Explanation: 

∴ 5+4+3+0 = 12
Question 54

What does the following program print?

#include
void f(int *p, int *q)
{
  p = q;
 *p = 2;
}
int i = 0, j = 1;
int main()
{
  f(&i, &j);
  printf("%d %d n", i, j);
  getchar();
  return 0;
}
A
2 2
B
2 1
C
0 1
D
0 2
       Programming       C-Programming       GATE 2010
Question 54 Explanation: 

Both pointers points to j = 1
now *p = 2
where j is updated with value 2.
printf (i, j) i = 0, j = 2
Question 55

What is the value printed by the following C program

#include
int f(int *a, int n)
{
  if(n <= 0) return 0;
  else if(*a % 2 == 0) return *a + f(a+1, n-1);
  else return *a - f(a+1, n-1);
}
  
int main()
{
  int a[] = {12, 7, 13, 4, 11, 6};
  printf("%d", f(a, 6));
  getchar();
  return 0;
}
A
-9
B
5
C
15
D
19
       Programming       C-Programming       GATE 2010
Question 55 Explanation: 
int a[ ] = {12, 7, 13, 4, 11, 6}
if (n <= 0)
return 0;
else if (*a % 2 = = 0)
return *a + f(a+1, n-1);
else
return *a – f(a+1, n-1);


⇒ 12+(7-(13-(4+(11-(6)))))
⇒ 12+(7-(13-(4+5)))
⇒ 12+7-(4)
⇒ 12+3
⇒ 15
Question 56

Consider the program below:

#include 
int fun(int n, int *f_p)
{
    int t, f;
    if (n <= 1)
    {
        *f_p = 1;
        return 1;
    }
    t = fun(n- 1,f_p);
    f = t+ * f_p;
    *f_p = t;
    return f;
}
 
int main()
{
    int x = 15;
    printf (" %d n", fun(5, &x));
    return 0;
}

The value printed is:

A
6
B
8
C
14
D
15
       Programming       C-Programming       GATE 2009
Question 56 Explanation: 
int x=15;
printf(fun(5,&x));
The code is implemented using Tail Recursion.
fun(5,15)

fun(4,15)

fun(3,15)

fun(2,15)

fun(1,15)
→ First we will trace fun(1,15) which returns 1.
→ Then trace fun(2,15) using fun(1,15) value, it returns 2.
→ Then fun(3,15), it returns 3≃(1+2)
→ Then fun(4,15), it returns 5=(2+3)
→ Then fun(5,15), it returns 8=(3+5)
If you call fun(6,15) then it will return 13=(5+8)
Here fun(n,*x)≃fun(n-1,&x)+fun(n-2,&x), where fun(n-1,&x) is storing in variable ‘t’ & fun(n-2,&x) is storing in variable x(*f-p).
∴ The program is nth Fibonacci number.
Question 57

Which combination of the integer variables x, y and z makes the variable a get the value 4 in the following expression?

     a = (x > y) ? ((x > z) ? x : z) : ((y > z) ? y : z) 
A
x = 3, y = 4, z = 2
B
x = 6, y = 5, z = 3
C
x = 6, y = 3, z = 5
D
x = 5, y = 4, z = 5
       Programming       C-Programming       GATE 2008
Question 57 Explanation: 
Required final output value of a=4.
→ We can directly eliminate the options B & C, because none of the variable can assign a value 4.
→ Given explanation is
a = (x>y)?((x>z)?x:z):((y>z)?y:z)
Option A:
x=3; y=4; z=2
a=(3>4)? ⇒ No
Then evaluate second expression ⇒ (4>2)?Yes
⇒a=y
a=4 (True)
Option D:
x=5; y=4; z=5
a=(5>4) ⇒ Yes
Then evaluate first expression ⇒ (5>5)? No
⇒ a=z ⇒ a=5 (Not true)
⇒ Answer is Option A.
Question 58

What is printed by the following C program?

int f(int x, int *py, int **ppz)           void main()
{                                               { 
  int y, z;                                      int c, *b, **a; 
  **ppz += 1; z = **ppz;                         c = 4; b = &c; a = &b;
  *py += 2; y = *py;                             printf("%d",f(c,b,a)); 
  x += 3;                                       }  
  return x + y + z;                                       
}  
A
18
B
19
C
21
D
22
       Programming       C-Programming       GATE 2008
Question 58 Explanation: 
f(c,b,a)
f(c,&c,&(&c)) = f(4,4,4)
c is 4, b is a pointer pointing address of a, a is a pointer to pointer of c. Hence both b and c are pointing to same memory address i.e., a.
Hence whatever increment operation happens in f, it happens/ reflects on same value i.e., a.
**ppz+=1;
z=**ppz; //z=5
These steps update it to 5 and stored in z.
*py+=2; //changes c to 7, x is unchanged.
y=*py; //y=7
It updates to 7 and stored in y.
x+=3 //x is incremented by 3.
returns x+y+z = 7+7+5 = 19
Question 59

Choose the correct option to fill ?1 and ?2 so that the program below prints an input string in reverse order. Assume that the input string is terminated by a newline character.

void reverse(void)
 {
  int c;
  if(?1)reverse();
  ?2
}
int main(){
  printf("Enter Text"); printf("n");
  reverse();printf("n") ;
}
A
?1 is (getchar( ) != ’\n’)
?2 is getchar(c);
B
?1 is (c = getchar( ) ) != ’\n’)
?2 is getchar(c);
C
?1 is (c != ’\n’)
?2 is putchar(c);
D
?1 is ((c = getchar()) != ’\n’)
?2 is putchar(c);
       Programming       C-Programming       GATE 2008
Question 59 Explanation: 
void reverse(void)
{
int c;
if(?1) reverse( );
?2
}
main( )
{
printf(“Enter Text”);
printf(“\n”);
reverse( );
printf(“\n”);
}
We can simply eliminate A & B for ?2.
& Hence
?1 is ((c=getchar( )) != ‘\n’)
?2 is putchar(c);
Question 60

Consider the following C program

int f1 (int n)
{
  if(n == 0||n == 1)
    return n;
  else
    return (2*f1(n-1)+3*f1(n-2));
}
 
int f2 (int n)
{
  int i;
  int X[N], Y[N], Z[N];

  X[0]=Y[0]=Z[0]=0;
  X[1]=1; Y[1]=2; Z[1]=3;
  for(i=2; i<=n; i++) {
    X[i] = Y[i-1] + Z[i-2];
    Y[i] = 2*X[i];
    Z[i] = 3*X[i];
  }
  return X[n];
}

f1(8) and f2(8) return the values

A
1661 and 1640
B
59 and 59
C
1640 and 1640
D
1640 and 1661
       Programming       C-Programming       GATE 2008
Question 60 Explanation: 
Both functions perform same operation, so output is same, means either (B) or (C) is correct.
f1(2) = 2*f1(1) + 3*f1(0) = 2
f1(3) = 2*f1(2) + 3*f1(1) = 2*2 + 3*1 = 7
f1(4) = 2*f1(3) + 3*f1(2) = 2*7 + 3*2 = 20
f1(5) = 2*f1(4) + 3*f1(3) = 2*20 + 3*7 = 40 + 21 = 61
We can skip after this as the only remaining choice is (C).
f1(6) = 2*f1(5) + 3*f1(4) = 2*61 + 3*20 = 122 + 60 = 182
f1(7) = 2*f1(6) + 3*f1(5) = 2*182 + 3*61 = 364 + 183 = 547
f1(8) = 2*f1(7) + 3*f1(6) = 2*547 + 3*182 = 1094 + 546 = 1640
Question 61

Consider the following C function:

#include
int f(int n)
{
    static int r = 0;
    if (n <= 0) return 1;
    if (n > 3)
    {
        r = n;
        return f(n-2)+2;
    }
    return f(n-1)+r;
}
 
int main()
{
    printf("%d", f(5));
}

What is the value of f(5)?

A
5
B
7
C
9
D
18
       Programming       C-Programming       GATE 2007
Question 61 Explanation: 
We need to evaluate f(5)
f(5) = f(3) + 2
f(3) = f(2) + 5 (where r is static and value of r=5)
f(2) = f(1) + 5
f(1) = f(0) + 5
f(0) = 1
⟹ f(5) = 1+5+5+5+2 = 18
Question 62

Consider the following code written in a pass-by-reference language like FORTRAN and these statements about the code.

            subroutine swap(ix,iy)
                    it = ix
            L1 :    ix = iy
            L2 :    iy = it
                end
                ia = 3
                ib = 8
                call swap (ia, 1b+5)
                print *, ia, ib
                end 
S1: The compiler will generate code to allocate a temporary nameless cell, 
    initialize it to 13, and pass the address of the cell swap  
S2: On execution the code will generate a runtime error on line L1 
S3: On execution the code will generate a runtime error on line L2 
S4: The program will print 13 and 8 
S5: The program will print 13 and -2 

Exactly the following set of statement(s) is correct:

A
S1 and S2
B
S1 and S4
C
S3
D
S1 and S5
       Programming       FORTRAN       GATE 2006
Question 62 Explanation: 
Swap operation perform between the ia and temporary nameless cell, therefore the value of ib is remains unchanged.
Swap (8, 13)
⇒ ia will returns value with 13.
⇒ ib is unchanged, because here we using pass by reference value.
➝ Temporary nameless is initialized to 13.
➝ There is No runtime error.
Question 63

Consider this C code to swap two integers and these five statements after it:

void swap(int *px, int *py) { 
   *px = *px - *py; 
   *py = *px + *py; 
   *px = *py - *px; 
}
S1: will generate a compilation error 
S2: may generate a segmentation fault at runtime depending on the arguments passed 
S3: correctly implements the swap procedure for all input pointers referring 
    to integers  stored in memory locations accessible to the process 
S4: implements the swap procedure correctly for some but not all valid input pointers 
S5: may add or subtract integers and pointers.
A
S1
B
S2 and S3
C
S2 and S4
D
S2 and S5
       Programming       C-Programming       GATE 2006
Question 63 Explanation: 
S2:
We may get the segmentation fault if the pointer values are constant (i.e., px or py) (or) (px or py) are points to a memory location is invalid.
S4:
Swap procedure can be implemented correctly but not for all input pointers because arithmetic overflow may occur based on input values.
Question 64

What does the following C-statement declare?

    int ( * f) (int * ) ; 
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.
       Programming       C-Programming       GATE 2005
Question 64 Explanation: 
int ( * f) (int * )
→ A pointer to a function which takes integer as a pointer and return an integer value.
Question 65

A common property of logic programming languages and functional languages is:

A
both are procedural languages
B
both are based on λ-calculus
C
both are declarative
D
both use Horn-clauses
       Programming       Programming-Paradigm       GATE 2005
Question 65 Explanation: 
Functional and logic programming languages are also called declarative languages; programs in these languages are said to describe (declaratively) what to do and not (operationally) how to do it.
Question 66

Which one of the following are essential features of an object-oriented programming language?

    (i) Abstraction and encapsulation
    (ii) Strictly-typedness
    (iii) Type-safe property coupled with sub-type rule
    (iv) Polymorphism in the presence of inheritance
A
(i) and (ii) only
B
(i) and (iv) only
C
(i), (ii) and (iv) only
D
(i), (iii) and (iv) only
       Programming       Programming-Paradigm       GATE 2005
Question 66 Explanation: 
Abstraction, encapsulation and inheritance are three main features of OOP language.
Question 67

Consider the following C-program:

void foo(int n, int sum) {
  int k = 0, j = 0;
  if (n == 0) return;
  k = n % 10; j = n / 10;
  sum = sum + k;
  foo(j, sum);
  printf ("%d,", k);
}
  
int main () {
  int a = 2048, sum = 0;
  foo(a, sum);
  printf ("%d\n", sum);
}

What does the above program print?

A
8, 4, 0, 2, 14
B
8, 4, 0, 2, 0
C
2, 0, 4, 8, 14
D
2, 0, 4, 8, 0
       Programming       C-Programming       GATE 2005
Question 67 Explanation: 
Int a=2048, Sum=0
⇒ foo (a, sum) = foo (2048,0)
⇒ n == 2048
⇒ k = n%10 = 2048%10 = 8
⇒ j = n/10 = 2048/10 = 204
Sum = Sum+k = 0+8 = 8
foo(j, sum) = foo(204, 8)
⇒ n=204
k = n%10 = 204%10 = 4
j = n/10 = 204/10 = 20
sum = sum+k = 12+0 = 12
foo(j, sum) =foo(2,12)
⇒ n=2
k = n%10 = 2%10 = 2
j = n/10 = 2/10 = 0
sum = 14
foo(0,14) ⇒ n==0
printf("%d", k) ⇒ k = 2, 0, 4, 8
After foo( ) statement one more printf statement is there then if print 0 after all digits of n.
2, 0, 4, 8, 0.
Question 68

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:

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
       Programming       C-Programming       GATE 2005
Question 68 Explanation: 
When a function is called before its declaration then it leads to compiler error.
Question 69

Consider the following C function.

void swap (int a, int b)
{
   int temp;
   temp = a;
   a = b;
   b = temp;
}

In order to exchange the values of two variables x and y.

A
call swap (x, y)
B
call swap (&x, &y)
C
swap (x,y) cannot be used as it does not return any value
D
swap (x,y) cannot be used as the parameters are passed by value
       Programming       C-Programming       GATE 2004
Question 69 Explanation: 
Option A:
Here parameters passed by value in C then there is no change in the values.
Option B:
Here values are not swap.
Here parameters are passed by address in C.
Option C:
It is false. Return value is not valid for exchanging the variables.
Option D:
It is correct.
We cannot use swap(x,y) because parameters are passed by value.
Only exchanging the values (or) variables are passing their address and then modify the content with the help of dereferencing operator(*).
Question 70

Consider the following C function:

     int f(int n)
     {
        static int i = 1;
        if (n >= 5)
           return n;
        n = n+i;
        i++;
        return f(n);
     } 

The value returned by f(1) is

A
5
B
6
C
7
D
8
       Programming       C-Programming       GATE 2004
Question 70 Explanation: 

The value return by f(1) = 7
Question 71

Consider the following program fragment for reversing the digits in a given integer to obtain a new integer. Let n = d1d2…dm.

     int n, rev;
     rev = 0;
     while (n > 0)
     {
        rev = rev*10 + n%10;
        n = n/10;
     }

The loop invariant condition at the end of the ith iteration is:

A
n = d1d2…dm-i and rev = dmdm-1…dm-i+1
B
n = dm-i+1…dm-1dm or rev = dm-i…d2d1
C
n ≠ rev
D
n = d1d2…dm and rev = dm…d2d1
       Programming       Loop-Invariants       GATE 2004
Question 71 Explanation: 
In each iteration the right most digit of n is going to make to the right end of the reverse.
Question 72

Consider the following C program segment:

     char p[20];
     char *s = "string";
     int length = strlen(s);
     int i;
     for (i = 0; i < length; i++)
          p[i] = s[length — i];
     printf("%s",p); 

The output of the program is

A
gnirts
B
string
C
gnirt
D
no output is printed
       Programming       C-Programming       GATE 2004
Question 72 Explanation: 
Every string is to be end with '\0'.
P[0] = S[7-1] = S[6] = \0.
In P[ ], the first character is '\0'. Then it will results a empty string. If P[0] become '\0', then it doesn't consider about next values in sequence.
Question 73

It is desired to design an object-oriented employee record system for a company. Each employee has a name, unique id and salary. Employees belong to different categories and their salary is determined by their category. The functions to get Name, getld and compute salary are required. Given the class hierarchy below, possible locations for these functions are:

    (i) getld is implemented in the superclass
    (ii) getld is implemented in the subclass
    (iii) getName is an abstract function in the superclass
    (iv) getName is implemented in the superclass
    (v) getName is implemented in the subclass
    (vi) getSalary is an abstract function in the superclass
    (vii) getSalary is implemented in the superclass
    (viii) getSalary is implemented in the subclass

Choose the best design

A
(i), (iv), (vi), (viii)
B
(i), (iv), (vii)
C
(i), (iii), (v), (vi), (viii)
D
(ii), (v), (viii)
       Programming       OOPS       GATE 2004
Question 73 Explanation: 
Name and id are a property of every employee and independent of their category. So these should be implemented in superclass. Every employee has a salary but this is determined by their category. So getsalary must be abstract function in superclass and implemented in subclass.
Question 74

Consider the following C program

     main()
     {   int x, y, m, n;
         scanf ("%d %d", &x, &y);
         /* Assume x > 0 and y > 0  */
         m = x; n = y;
         while (m! = n)
            {    if (m > n)
                   m = m - n;
                 else
                   n = n - m;
            } 
          print f ("% d", n);
          }

The program computes

A
x + y using repeated subtraction
B
x mod y using repeated subtraction
C
the greatest common divisor of x and y
D
the least common multiple of x and y
       Programming       C-Programming       GATE 2004
Question 74 Explanation: 
Given code is same as Euclid's Algorithm for finding Greatest Common Divisor(GCD).
Question 75

Choose the best matching between the programming styles in Group 1 and their characteristics in Group 2.

      Group-1		        Group-2 
 P. Functional	      1. Command-based, procedural
 Q. Logic	      2. Imperative, abstract data type
 R. Object-oriented   3. Side-effect free, declarative, expression evaluation
 S. Imperative	      4. Declarative, clausal representation, theorem proving 
A
P - 2, Q - 3, R - 4, S - 1
B
P - 4, Q - 3, R - 2, S - 1
C
P - 3, Q - 4, R - 1, S - 2
D
P - 3, Q - 4, R - 2, S - 1
       Programming       Match-the-Following       GATE 2004
Question 75 Explanation: 
P) Functional programming is declarative in nature, involves expression evaluation and side effect free.
Q) Logic is also declarative but involves theorem proving.
R) Object oriented is imperative statement based and have abstract data types.
S) Imperative programs are made giving commands and follow definite procedure.
Question 76

Consider the following logic program P

A(x) <- B(x, y), C(y) 
     <- B(x,x) 

Which of the following first order sentences is equivalent to P?

A
(∀x) [(∃y) [B(x,y) ∧ C(y)] ⇒ A(x)] ∧ ¬(∃x)[B(x,x)]
B
(∀x) [(∀y) [B(x,y) ∧ C(y)] ⇒ A(x)] ∧ ¬(∃x)[B(x,x)]
C
(∀x) [(∃y) [B(x,y) ∧ C(y)] ⇒ A(x)] ∨ ¬(∃x)[B(x,x)]
D
(∀x) [(∀y) [B(x,y) ∧ C(y)] ⇒ A(x)] ∧ (∃x)[B(x,x)]
       Programming       Logic-Programming       GATE 2003
Question 76 Explanation: 
Note: This is not in gate syllabus. Please ignore this question.
Question 77

The following program fragment is written in a programming language that allows variables and does not allow nested declarations of functions.

global int i = 100, j = 5;
void P(x)
{
    int i = 10;
    print(x + 10);
    i = 200;
    j = 20;
    print(x);
}
main()
{
    P(i + j);
}

If the programming language uses static scoping and call by need parameter passing mechanism, the values printed by the above program are

A
115, 220
B
25, 220
C
25, 15
D
115, 105
       Programming       Parameter-Passing       GATE 2003
Question 77 Explanation: 
P(i+j)
P(100+5) = P(105)
→void P(105)
{   
int i=10;   
print (x+10);  ⇒ 105+10=115 prints
  i=200;  
  j = 20;  
  print (x);  ⇒ x=105 prints
}  
115, 105 prints
Question 78

The following program fragment is written in a programming language that allows variables and does not allow nested declarations of functions.

global int i = 100, j = 5;
void P(x)
{
    int i = 10;
    print(x + 10);
    i = 200;
    j = 20;
    print(x);
}
main()
{
    P(i + j);
}

If the programming language uses dynamic scoping and call by name parameter passing mechanism, the values printed by the above program are:

A
115, 220
B
25, 220
C
25, 15
D
115, 105
       Programming       Parameter-Passing       GATE 2003
Question 78 Explanation: 
In dynamic,
In void P(x)
{  int i = 10;
   print(x + 10);   ⇒ 105+10 = 115 prints
 
print (x);   ⇒ print x=220;
Question 79

Consider the following class definitions in a hypothetical Object Oriented language that supports inheritance and uses dynamic binding. The language should not be assumed to be either Java or C++, though the syntax is similar.

Class P {
    void f(int i) {
        print(i);
    }
}

Class Q subclass of P {
    void f(int i) {
        print(2*i);
    }
} 

Now consider the following program fragment:

Px = new Q();
Qy = new Q();
Pz = new Q();
x.f(1); ((P)y).f(1); z.f(1); 

Here ((P)y) denotes a typecast of y to P. The output produced by executing the above program fragment will be

A
1 2 1
B
2 1 1
C
2 1 2
D
2 2 2
       Programming       Variable Binding       GATE 2003
Question 79 Explanation: 
Because of using dynamic binding it results a values such as 2 2 2.
Note: The given question is not in the present syllabus
Question 80

In the following C program fragment, j, k n and TwoLog_n are interger variables, and A is an array of integers. The variable n is initialized to an integer ≥3, and TwoLog_n is initialized to the value of 2*⌈log2(n)⌉

   for (k = 3; k < = n; k++)
               A[k] = 0;
   for (k = 2; k < = TwoLog_n; k++)
          for (j = k + 1; j < = n; j++)
                    A[j] = A[j] || (j%k);
   for (j = 3; j < = n; j++)
          if (!A[j]) printf("%d", j); 

The set of numbers printed by this program fragment is

A
{m|m ≤ n, (∃i)[m=i!]}
B
{m|m ≤ n, (∃i)[m=i2]}
C
{m|m ≤ n, m is prime}
D
{ }
       Programming       C-Programming       GATE 2003
Question 80 Explanation: 
Take n=4, so Two log_n=4
Now Trace the code,
for (k=3; k<=n; k++)
A[k]=0; // A[3]=0
A[4]=0
for (k=2; k<=Two log_n; k++)
for(j=k+1; j<=n; j++)
A[j] = A[j] // (j%k); // A[3] = 0 // I=1
A[4] = 0 // I=1
for (j=3; j<=n; j++)
if (!A[j]) printf("%d", j);
// if (!1) means if (0), so printf will never execute
Hence, Option (D) is the answer.
Question 81

Consider the C program shown below.

#include 
#define print(x) printf("%d", x)
int x;
void Q(int z)
{
    z += x;
    print(z);
}
void P(int *y)
{
    int x = *y + 2;
    Q(x);
    *y = x - 1;
    print(x);
}
main(void)
{
    x = 5;
    P(&x);
    print(x);
} 

The output of this program is

A
12 7 6
B
22 12 11
C
14 6 6
D
7 6 6
       Programming       C-Programming       GATE 2003
Question 81 Explanation: 
In main function x=5; it is global array
p(&x) it goes to P( ) function
y=5
x=5+2=7;
Q(x)
z=7
z=7+5=12(Print+z→I)
comes to P( )
*y=7-1=6
x=7(Print x→II)
comes to main ( ),
print x=*y=6 (print x→III)
Output: 12 7 6
Question 82

In the C language

A
At most one activation record exists between the current activation record and the activation record for the main
B
The number of activation records between the current activation record and the activation record for the main depends on the actual function calling sequence.
C
The visibility of global variables depends on the actual function calling sequence.
D
Recursion requires the activation record for the recursive function to be saved on a different stack before the recursive fraction can be called.
       Programming       C-Programming       GATE 2002
Question 82 Explanation: 
In C Language a function can create activation record from the created function stack.
Question 83

What is printed by the print statements in the program P1 assuming call by reference parameter passing?

Program P1()
{
   x = 10;
   y = 3;
   func1(y,x,x);
   print x;
   print y;
}
func1(x,y,z)
{
   y = y+4;
   z = x+y+z;
} 
A
10, 3
B
31, 3
C
27, 7
D
None of the above
       Programming       Parameter-Passing       GATE 2001
Question 83 Explanation: 
Here, variable x of func1 points to address of variable y.
And variable y and z of func1 points to address of variable x.
Therefore, y = y+4 ⇒ y = 10+4 = 14
and z = x+y+z ⇒ z = 14+14+3 = 31
z will be stored back in k.
Hence, x=31 and y will remain as it is (y=3).
Hence, answer is (B).
Question 84

Consider the following program

                Program P2 
                   var n: int: 
                   procedure W(var x: int) 
                   begin 
                          x=x+1; 
                          print x;   
                   end 

                procedure D 
                begin  
                          var n: int; 
                          n=3; 
                          W(n);  
                End 
            begin               //beginP2 
                n=10; 
                D; 
            end  

If the language has dynamic scoping and parameters are passed by reference, what will be printed by the program?

A
10
B
11
C
3
D
None of the above
       Programming       Programming       GATE 2001
Question 84 Explanation: 
n=3
W(n)=W(3)
Procedure W(var x; int)
begin
x = x+1 = 3+1 = 4
Print x → Print x=4
end
Question 85

Consider the following C program:

           void abc(char*s)
           {
              if(s[0]==’\0’)return;
              abc(s+1);
              abc(s+1);
              printf(“%c”,s[0]);
           }
           main()
           {  abc(“123”)
           }  

(a) What will be the output of the program?
(b) If abc(s) is called with a null-terminated string s of length n characters (not counting the null (‘\0’) character), how many characters will be printed by abc(s)?

A
Theory Explanation is given below.
       Programming       C-Programming       GATE 2001
Question 86

The following C declarations

struct node
{
   int i;
   float j;
};
struct node *s[10]; 

define s to be

A
An array, each element of which is a pointer to a structure of type node
B
A structure of 2 fields, each field being a pointer to an array of 10 elements
C
A structure of 3 fields: an integer, a float, and an array of 10 elements
D
An array, each element of which is a structure of type node
       Programming       C-Programming       GATE 2000
Question 86 Explanation: 
The given code represents an array of s[ ], in this each element is a pointer to structure of type node.
Question 87

The most appropriate matching for the following pairs

    X: m=malloc(5); m= NULL;        1: using dangling pointers
    Y: free(n); n->value=5;         2: using uninitialized pointers
    Z: char *p; *p = ’a’;           3. lost memory  

is:

A
X – 1 Y – 3 Z – 2
B
X – 2 Y – 1 Z – 3
C
X – 3 Y – 2 Z – 1
D
X – 3 Y – 1 Z – 2
       Programming       Match-the-Following       GATE 2000
Question 87 Explanation: 
X → m = NULL will results the loss of memory.
Y → n is pointer to invalid memory, a making it as a dangling pointer.
Z → p is not initialized.
p = malloc (size of(char))p = malloc (size of(char)); should have been used before assigning 'aa' to ∗p.
Question 88

Aliasing in the context of programming languages refers to

A
multiple variables having the same memory location
B
multiple variables having the same value
C
multiple variables having the same identifier
D
multiple uses of the same variable
       Programming       Aliasing       GATE 2000
Question 88 Explanation: 
In computer programming, aliasing refers to the situation where the same memory location can be accessed using different names.
Question 89

Consider the following C declaration

struct {
    short s [5]
    union {
    float y;
    long z;
    } u;
} t; 

Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment considerations, is

A
22 bytes
B
14 bytes
C
18 bytes
D
10 bytes
       Programming       C-Programming       GATE 2000
Question 89 Explanation: 
short [5] = 5×2 = 10
max[float, long] = max [4, 8] = 8
Total = short[5] + max[float,long] = 10 + 8 = 18
Question 90

The value of j at the end of the execution of the following C program.

int incr(int i)
{
   static int count = 0;
   count = count + i;
   return (count);
}
main()
{
   int i,j;
   for (i = 0; i <= 4; i++)
      j = incr(i);
} 

is

A
10
B
4
C
6
D
7
       Programming       C-Programming       GATE 2000
Question 90 Explanation: 
At i=0; count=0
i=1; count=1
i=2; count=3
i=3; count=6
i=4; count=10
It return count value is 10.
Question 91

Consider the following program is pseudo-Pascal syntax.

    program main;
       var x: integer;
       procedure Q [z:integer);
       begin
          z: z + x;
          writeln(z)
       end;
    procedure P (y:integer);
          var x: integer;
       begin
          x: y + 2;
          Q(x);
          writeln(x)
       end;
       begin 
          x:=5;
          P(x);
          Q(x);
          writeln(x)
       end. 

What is the output of the program, when
(a) The parameter passing mechanism is call-by-value and the scope rule is static scooping?

(b) The parameter passing mechanism is call-by-reference and the scope rule is dynamic scooping?

A
Theory Explanation is given below.
       Programming       Descriptive       GATE 2000
Question 91 Explanation: 
Note: Out of syllabus.
Question 92

Given the programming constructs (i) assignment (ii) for loops where the loop parameter cannot be changed within the loop (iii) if-then-else (iv) forward go to (v) arbitrary go to (vi) non-recursive procedure call (vii) recursive procedure/function call (viii) repeat loop, which constructs will you not include in a programming language such that it should be possible to program the terminates (i.e., halting) function in the same programming language.

A
(ii), (iii), (iv)
B
(v), (vii), (viii)
C
(vi), (vii), (viii)
D
(iii), (vii), (viii)
       Programming       Programming-Constructs       GATE 1999
Question 92 Explanation: 
Arbitrary goto, recursive call and repeat loop may enter infinite loop and the program might never terminate.
Question 93

Consider the following C function definition.

int Trial (int a, int b, int c)
{
    if ((a >= b) && (c < b) return b;
    else if (a >= b) return Trial(a, c, b);
    else return Trial(b, a, c);
} 

The function Trial:

A
Finds the maximum of a, b, and c
B
Finds the minimum of a, b and c
C
Finds the middle number of a, b, c
D
None of the above
       Programming       C-Programming       GATE 1999
Question 93 Explanation: 
Try for (3,2,2), it will go for infinite loop.
Question 94

What value would the following function return for the input x=95?

                 Function fun (x:integer):integer;
      Begin
                 If x > 100 then fun = x - 10
                 Else fun = fun(fun(x + 11))
      End;  
A
89
B
90
C
91
D
92
       Programming       Programming       GATE 1998
Question 94 Explanation: 
Value returned by
fun(95) = fun(fun(106))
= fun(96)
= fun(fun(107))
= fun(97)
= fun(fun(108))
= fun(98)
= fun(fun(109))
= fun(99)
= fun(110)
= fun(100)
= fun(fun(111))
= fun(101)
= 91
Question 95

What is the result of the following program?

program side-effect (input, output);
    var x, result: integer;
    function f (var x:integer):integer;
    begin
        x:x+1;f:=x;
    end;
begin
    x:=5;
    result:=f(x)*f(x);
    writeln(result);
end; 
A
5
B
25
C
36
D
42
       Programming       Programming       GATE 1998
Question 95 Explanation: 
If it is call by reference then answer is 42.
If it is call by value then answer is 36.
Question 96

Given the following Pascal-like program segment

Procedure A;
  x,y: integer;
   Procedure B;
    x,z: real
    S1
   end B;
   Procedure C;
      i: integer;
       S2
   end C;
end A; 

The variables accessible in S1 and S2 are

A
x or A, y, x of B and z in S1 and
x of B, y and i in S2
B
x or B, y and z in S1 and
x of B, i and z in S2
C
x or B, z and y in S1 and
x of A, i and y in S2
D
None of the above
       Programming       PASCAL-Programming       GATE 1997
Question 96 Explanation: 
Note: Out of syllabus.
Question 97

In the following Pascal program segment, what is the value of X after the execution of the program segment?
X:=-10; Y:=20;
If X > Y then if X < 0 then X:=abs(X) else X:=2*X;

A
10
B
-20
C
-10
D
None
       Programming       PASCAL-Programming       GATE 1995
Question 97 Explanation: 
X is remains unchanged. As the if condition is becomes false.
X = -10
Question 98

Which of the following strings can definitely be said to be tokens without looking at the next input character while compiling a Pascal program?

 I. begin           II. program           III. <>   
A
I
B
II
C
III
D
All of the above
       Programming       Pascal Programming       GATE 1995
Question 98 Explanation: 
Note: Out of syllabus.
Question 99

Assume that X and Y are non-zero positive integers. What does the following Pascal program segment do?

 while X <>Y do
 if X > Y then
    X := X – Y
 else
    Y := Y – X;
 write(X); 
A
Computes the LCM of two numbers
B
Divides the larger number by the smaller number
C
Computes the GCD of two numbers
D
None of the above
       Programming       PASCAL-Programming       GATE 1995
Question 99 Explanation: 
Let X=3 and Y=5
1st pass : X=3 and Y=2
2nd pass : X=1 and Y=2
3rd pass : X=1 and Y=1
Write(X), which writes 1. Which is nothing but GCD of 3 & 5.
Question 100

What is the value of X printed by the following program?

 program COMPUTE (input, output);
    var
                  X:integer;
    procedure FIND (X:real);
                  begin
                  X:=sqrt(X);
                  end;
   begin
                  X:=2
                  Find(X)
                  Writeln(X)
   end 
A
2
B
√2
C
Run time error
D
None of the above
       Programming       Programming       GATE 1995
Question 100 Explanation: 
Since nothing is said in question. So we will assume by default call by value.
X in the procedure FIND is a local variable. No change will be reflected in global variable X.
Question 101

A variant record in Pascal is defined by

                    type varirec      =   record
                                          number : integer;
                                          case (var1,var2) of
                                          var1: (x,y : integer);
                                          var2: (p.q.: real)
                        end
                    end   

Suppose an array of 100 records was declared on a machine which uses 4 bytes for an integer and 8 bytes for a real. How much space would the compiler have to reserve for the array?

A
2800
B
2400
C
2000
D
1200
       Programming       PASCAL-Programming       GATE 1995
Question 101 Explanation: 
Note: Out of syllabus.
Question 102

Consider the following C functions.

  int fun1 (int n)  {                              int fun2 (int n)  {
    static int i = 0;                                static int i = 0;  
    if (n > 0)  {                                    if (n > 0)  { 
       ++i;                                              i = i + fun1 (n);   
       fun1 (n-1);                                       fun2 (n-1);
    }                                                 }
    return (i);                                           return (i);
  }                                                 } 

The return value of fun2 (5) is _______.

A
55
       Programming       Functions       GATE 2020
Question 102 Explanation: 
#include
int fun1(int n) {
printf("--fun1 call--\n");
static int i = 0;
if(n>0){
++i;
printf("fun1(%d-1)\n",n);
fun1(n-1);
}
printf("fun1(%d)= %d\n",n, i);
return(i);
}
int fun2(int n) {
printf("\n******* fun2 call ********\n");
static int i = 0;
if(n>0){
printf("%d + fun1(%d)\n", i,n);
i=i+fun1(n);
fun2(n-1);
}
printf("fun2(%d)= %d\n",n, i);
return(i);
}
void main()
{
printf("final = %d\n", fun2(5));
}
Check step by step hand run of the code to understand the recursion:
******* fun2 call ********
0 + fun1(5)
--fun1 call--
fun1(5-1)
--fun1 call--
fun1(4-1)
--fun1 call--
fun1(3-1)
--fun1 call--
fun1(2-1)
--fun1 call--
fun1(1-1)
--fun1 call--
fun1(0)= 5
fun1(1)= 5
fun1(2)= 5
fun1(3)= 5
fun1(4)= 5
fun1(5)= 5
******* fun2 call ********
5 + fun1(4)
--fun1 call--
fun1(4-1)
--fun1 call--
fun1(3-1)
--fun1 call--
fun1(2-1)
--fun1 call--
fun1(1-1)
--fun1 call--
fun1(0)= 9
fun1(1)= 9
fun1(2)= 9
fun1(3)= 9
fun1(4)= 9
******* fun2 call ********
14 + fun1(3)
--fun1 call--
fun1(3-1)
--fun1 call--
fun1(2-1)
--fun1 call--
fun1(1-1)
--fun1 call--
fun1(0)= 12
fun1(1)= 12
fun1(2)= 12
fun1(3)= 12
******* fun2 call ********
26 + fun1(2)
--fun1 call--
fun1(2-1)
--fun1 call--
fun1(1-1)
--fun1 call--
fun1(0)= 14
fun1(1)= 14
fun1(2)= 14
******* fun2 call ********
40 + fun1(1)
--fun1 call--
fun1(1-1)
--fun1 call--
fun1(0)= 15
fun1(1)= 15
******* fun2 call ********
fun2(0)= 55
fun2(1)= 55
fun2(2)= 55
fun2(3)= 55
fun2(4)= 55
fun2(5)= 55
final = 55
Question 103
Consider the following C functions.
int tob (int b, int* arr) {
int i;
for (i=0; b>0; i++) {
if (b%2) arr [i] = 1;
else arr [i] = 0;
b = b/2;
}
return (i);
}

int pp (int a, int b) {
int arr [20];
int i, tot = 1, ex, len;
ex = a;
len = tob (b,arr);
for (i=0; i if (arr[i] == 1)
tot = tot * ex;
ex = ex * ex;
}
return (tot);
}
The value returned by pp(3,4) is ________.
A
81
       Programming       Functions       GATE 2020
Question 103 Explanation: 
pp(3,4) ⇒
a=3,b=4
tot=1
ex=a=3
len=tob(b,arr) which is 3
[
tob(4,arr)==>
b=4
b%2 =4%2=0 Condition is false then arr[0]=0
=> b=b/2 =4/2 =2
b=2
b%2 =2%2=0 condition is false then arr[1]=0
=>b=b/2=2/2=1
b=1
then b%2=1%2 condition is true then arr[2]=1
=>b=b/2=1/2=0
The i value is 3 [length is 3]
]
i=0,
arr[0] ==1 condition is false
ex=3*3=9
i=1
arr[1]==1 condition is false
then
ex=9*9=81
i=2
then arr[2]==1 condition is true
tot=tot*ex=1*81=81
ex=81*81
Finally it returns tot value which 81.
Question 104
Program PARAM (input, output);
 var m, n : integer;
 procedure P (var, x, y : integer);
    var m : integer;
    begin
      m : = 1;
      x : = y + 1
    end;
 procedure Q (x:integer; vary : integer);
    begin
      x:=y+1;
    end;
 begin
    m:=0; P(m,m); write (m);
    n:=0; Q(n*1,n); write (n)
 end 

The value of m, output by the program PARAM is:

A
1, because m is a local variable in P
B
0, because m is the actual parameter that corresponds to the formal parameter in p
C
0, because both x and y are just reference to m, and y has the value 0
D
1, because both x and y are just references to m which gets modified in procedure P
E
none of the above
       Programming       Programming       GATE 1993
Question 104 Explanation: 
0, because global m is not modified, m is just passed to formal argument of P.
Question 105
Program PARAM (input, output);
 var m, n : integer;
 procedure P (var, x, y : integer);
    var m : integer;
    begin
      m : = 1;
      x : = y + 1
    end;
 procedure Q (x:integer; vary : integer);
    begin
      x:=y+1;
    end;
 begin
    m:=0; P(m,m); write (m);
    n:=0; Q(n*1,n); write (n)
 end 

The value of n, output by the program PARAM is:

A
0, because n is the actual parameter corresponding to x in procedure Q.
B
0, because n is the actual parameter to y in procedure Q.
C
1, because n is the actual parameter corresponding to x in procedure Q.
D
1, because n is the actual parameter corresponding to y in procedure Q.
E
none of the above
       Programming       Programming       GATE 1993
Question 105 Explanation: 
0, because n is just passed to formal parameters of Q and no modification in global n.
Question 106
Program PARAM (input, output);
 var m, n : integer;
 procedure P (var, x, y : integer);
    var m : integer;
    begin
      m : = 1;
      x : = y + 1
    end;
 procedure Q (x:integer; vary : integer);
    begin
      x:=y+1;
    end;
 begin
    m:=0; P(m,m); write (m);
    n:=0; Q(n*1,n); write (n)
 end 

What is the scope of m declared in the main program?

A
PARAM, P, Q
B
PARAM, P
C
PARAM, Q
D
P, Q
E
none of the above
       Programming       Programming       GATE 1993
Question 106 Explanation: 
Since m is defined global it is visible inside all the procedures.
Question 107

What does the following code do?

 var a, b : integer;
 begin
    a:=a+b;
    b:=a-b;
    a:=a-b
 end; 
A
exchanges a and b
B
doubles a and stores in b
C
doubles b and stores in a
D
leaves a and b unchanged
E
none of the above
       Programming       Programming       GATE 1993
Question 107 Explanation: 
Exchanges a and b.
Let us consider a=5; b=2
a := a+b = 5+2 = 7
b := a-b = 7-2 = 5
a := a-b = 7-5 = 2
O/P: a=2; b=5
Question 108

Consider the following PASCAL program segment:

 if i mode 2 = 0 then
           while i > = 0 do
             begin
              i:=i div 2;
              if i mod 2 < > 0 do then i:=i – 1
                   else i:=i – 2
 end

An appropriate loop-invariant for the while-loop is ______

A
PASCAL is out of syllabus.
       Programming       PASCAL-Programming       GATE 1991
Question 109

Consider the following recursive definition of fib:

 fib (n) : = if n = 0 then 1
             else if n = 1 than 1
             else fib (n – 1) + fib (n – 2)

The number of times fib is called (including the first call) for an evaluation of fib (7) is ___________

A
41
       Programming       Recursion       GATE 1991
Question 109 Explanation: 
The recurrence relation for the no. of calls is
T(n) = T(n-1) + T(n-2) + 2
T(0) = T(1) = 0 (for fib(0) and fib(1), there are no extra recursive calls)
T(2) = 2
T(3) = 4
T(4) = 8
T(5) = 14
T(6) = 24
T(7) = 40
Counting the initial call, we get
40+1 = 41
Question 110

Choose the correct alternatives (more than one may be correct) and write the corresponding letters only: Consider the following Pascal function:

 function X (M:integer) : integer;
 var i:integer;
 begin
   i = 0;
   while i*i < M do i; =i+1
   X;=i
 end
The function call X(N), if N is positive, will return
A
(√N)
B
(√N)+1
C
[√N]
D
[√N]+1
E
None of the above
       Programming       PASCAL-Programming       GATE 1991
Question 110 Explanation: 
Note: Out of syllabus.
Question 111

Match the pairs in the following questions:

(a) Small talk      (p) Logic programming
(b) LISP            (q) Data flow programming
(c) Prolog          (r) Functional programming
(d) VAL             (s) Object-oriented programming
A
(a) - (s), (b) - (r), (c) - (p), (d) - (q)
       Programming       Match-the-Following       GATE 1990
Question 111 Explanation: 
Note: Out of syllabus.
Question 112

In which of the following case(s) is it possible to obtain different results for call-by-reference and call-by-name parameter passing?

A
Passing an expression as a parameter
B
Passing an array as a parameter
C
Passing a pointer as a parameter
D
Passing as array element as a parameter
E
Both A and D
       Programming       Parameter-Passing       GATE 1989
Question 112 Explanation: 
Option D:
Passing array element as a parameter.
Consider an example:
{
.......
a[ ] = {1, 2, 3, 4, 5}
fun (a[i]);
print a[0];
}
fun (int x)
{
int i=1;
}
O/P:
Call-by-reference: 6
Call-by-name: 1
Result is different.
Option A:
While we passing an expression as a parameter due to precedence (higher (or) lower), the output may changes.
If we pass 1+2 to the below function
int foo (int x)
{
return x*x;
}
O/P:
Call by reference = 3*3 = 9
Call by name = 1+2*1+2 (* has higher precedence e)
= 1+2+2
= 5
Output differs.
Answer: A, D
Question 113

An unrestricted use of the "go to" statement is harmful because of which of the following reason(s):

A
It makes it more difficult to verify programs.
B
It makes programs more inefficient.
C
It makes it more difficult to modify existing programs.
D
It results in the compiler generating longer machine code.
       Programming       Programming       GATE 1989
Question 113 Explanation: 
Dijkstra's argued that unrestricted goto statements should abolished from the higher-level languages because they complicated the task of analyzing and verifying the correctness of programs.
Question 114

Study the following program written in a block-structured language:

Var x, y:interger; 
procedure P(n:interger);
begin
     x:=(n+2)/(n-3);
end;

procedure Q 
Var x, y:interger;
begin   
    x:=3;
    y:=4; 
    P(y);
    Write(x)                                __(1)
end;
 
begin
    x:=7;
    y:=8;
    Q; 
Write(x);                                   __(2) 
end.

What will be printed by the write statements marked (1) and (2) in the program if the variables are statically scoped?

A
3, 6
B
6, 7
C
3, 7
D
None of the above.
       Programming       Programming       GATE 1987
Question 114 Explanation: 
First procedure Q is called from the main procedure. Q has local variables x and y with values 3 and 4 respectively. This local variable y (value 4) is being parsed to procedure P during call, and received in local variable n inside procedure P. Now as P does not have any local definition for variable x, it will assign the evaluated value of (n+2)/(n-3), i.e., (4+2)/(4-3)=6 to the global variable x, which was previously 7. After the call of procedure P, procedure Q writes the value of local variable x which is still 3. Lastly, the main procedure writes the value of global variable x, which has been changed to 6 inside procedure P. So, the output will be 3, 6.
Question 115

For the program given below what will be printed by the write statements marked (1) and (2) in the program if the variables are dynamically scoped?

Var x, y:interger; 
procedure P(n:interger);
begin
     x := (n+2)/(n-3);
end;

procedure Q 
Var x, y:interger;
begin   
    x:=3;
    y:=4; 
    P(y);
    Write(x);                                __(1)
end;
 
begin
    x:=7;
    y:=8;
    Q; 
    Write(x);                                __(2)
end.
A
3, 6
B
6, 7
C
3, 7
D
None of the above
       Programming       Programming       GATE 1987
Question 115 Explanation: 
The same sequence of statements will be executed using dynamic scoping. However, as there is no local definition of variable x in procedure P, it will consider the recent definition in the calling sequence, as P is being called from procedure Q, definition of x from Q will be changed to 6 from 3. Now, when Q writes local variables x, 6 will be printed. The write global variable x from main procedure will print 7 (as value of the global variable x has not been changed). So, the output will be 6, 7.
Question 116

Match the programming paradigms and languages given in the following table.

A
I-c, II-d, III-b, IV-a
B
I-a, II-d, III-c, IV-b
C
I-d, II-c, III-b, IV-a
D
I-c, II-d, III-a, IV-b
       Programming       Match-the-Following       GATE 2008-IT
Question 116 Explanation: 
Note: Out of syllabus.
Question 117

What is the output printed by the following C code?

# include 
int main ()
{
    char a [6] = "world";
    int i, j;
    for (i = 0, j = 5; i < j; a [i++] = a [j--]);
    printf ("%s\n", a);
}
A
dlrow
B
Null String
C
dlrld
D
worow
       Programming       C-Programming       GATE 2008-IT
Question 117 Explanation: 
As the base address or starting of the string "Null" is placed. So while reading array if Null comes it assumes that this is the end of array. So, it terminates here only.
Question 118

Consider the C program below. What does it print?

# include 
# define swapl (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);
}
A
5, 5
B
5, 4
C
4, 5
D
4, 4
       Programming       C-Programming       GATE 2008-IT
Question 118 Explanation: 
"If (num1 ≥ num2)
{Swap3 (&num1, &num2) ; }"
Statement is true, so call by reference will be performed and the value of num1 and num2 will get exchanged.
Question 119

Consider the C program given below. What does it print?

#include 
int main ()
{
        int i, j;
        int a [8] = {1, 2, 3, 4, 5, 6, 7, 8};
        for(i = 0; i < 3; i++) { a[i] = a[i] + 1; i++; } i--; for (j = 7; j > 4; j--) {
              int i = j/2;
              a[i] = a[i] - 1;
        }
        printf ("%d, %d", i, a[i]);
}
A
2, 3
B
2, 4
C
3, 2
D
3, 3
       Programming       C-Programming       GATE 2008-IT
Question 119 Explanation: 
Note that there are two variables named 'i', with different scope.
First for loop will run for i = 0, 2 and 4 as i is incremented twice and resultant array will be 'a' = 2, 2, 4, 4, 5, 6, 7, 8. Loop will terminate at i = 4.
After that value of 'i' will become '3' as there is a decremented operation after for loop.
Next for loop is running for j = 7, 6, 5 and corresponding 'i' values which is a local variable inside for loop will be
3(7/2), 3(6/2), 2(5/2)
Array after this for loop will be
a = 2, 2, 3, 2, 5, 6, 2, 8.
After the loop, current 'i' value is 3 and elements at a[3] = 2.
Question 120

C program is given below:

# include 
int main ()
{
        int i, j;
        char a [2] [3] = {{'a', 'b', 'c'}, {'d', 'e', 'f'}};
        char b [3] [2];
        char *p = *b;
        for (i = 0; i < 2; i++) {
              for (j = 0; j < 3; j++) {
              *(p + 2*j + i) = a [i] [j];
              }
        }
}
What should be the contents of the array b at the end of the program?
A
ab
cd
ef
B
ad
be
cf
C
ac
eb
df
D
ae
dc
bf
       Programming       C-Programming       GATE 2008-IT
Question 120 Explanation: 
*p = a[0][0] = a
*(p+2) = a[0][1] = b
*(p+4) = a[0][2] = c
*(p+1) = a[1][0] = d
*(p+3) = a[1][1] = e
*(p+5) = a[1][2] = f
Question 121

Consider the code fragment written in C below :

void f (int n)
{ 
  if (n <=1)  {
   printf ("%d", n);
  }
  else {
   f (n/2);
   printf ("%d", n%2);
  }
}

What does f(173) print?

A
010110101
B
010101101
C
10110101
D
10101101
       Programming       C-Programming       GATE 2008-IT
Question 121 Explanation: 

So, after traversing the tree we get:
10101101
Question 122

Consider the code fragment written in C below :

void f (int n)
{
    if (n <= 1)  {
        printf ("%d", n);
    }
    else {
        f (n/2);
        printf ("%d", n%2);
    }
}

Which of the following implementations will produce the same output for f(173) as the above code?

P1
void f (int n)
{
    if (n/2)  {
        f(n/2);
    }
    printf ("%d", n%2);
}

P2 
void f (int n)
{
    if (n <=1)  {
        printf ("%d", n);
    }
    else {
        printf ("%d", n%2);
        f (n/2);
    }
}
A
Both P1 and P2
B
P2 only
C
P1 only
D
Neither P1 nor P2
       Programming       C-Programming       GATE 2008-IT
Question 122 Explanation: 
P1 prints same as the original program.
But P2 prints the reverse of original sequence printed by original program.
Question 123

The function f is defined as follows:

int f (int n) {
       if (n <= 1) return 1;
       else if (n % 2  ==  0) return f(n/2);
       else return f(3n - 1);
} 
Assuming that arbitrarily large integers can be passed as a parameter to the function, consider the following statements.
(i) The function f terminates for finitely many different values of n ≥ 1.
(ii) The function f terminates for infinitely many different values of n ≥ 1.
(iii) The function f does not terminate for finitely many different values of n ≥ 1.
(iv) The function f does not terminate for infinitely many different values of n ≥ 1.
Which one of the following options is true of the above?

A
(i) and (iii)
B
(i) and (iv)
C
(ii) and (iii)
D
(ii) and (iv)
       Programming       Programming       GATE 2007-IT
Question 123 Explanation: 
The function can be terminated for all the values which can have factor of 2{(2-x)2 == 0}, so (i) is false and (ii) is true.
→ Let n=3, then it is terminated in 2nd iteration.
→ Let n=5, then sequence is 5→14→7→20→10 and it will repeat.
→ Any number with factor 5 and 2 leads to infinite recursion.
So, (iv) is True and (iii) is False.
Question 124

Consider the C program given below:

#include 
int main ()    {
    int sum = 0, maxsum = 0,  i,  n = 6;
    int a [] = {2, -2, -1, 3, 4, 2};
    for (i = 0; i < n; i++)    {
            if (i == 0 || a [i]  < 0  || a [i] < a [i - 1])  {
                     if (sum > maxsum) maxsum = sum;
                     sum = (a [i] > 0) ? a [i] : 0;
            }
            else sum += a [i];
    }
    if (sum > maxsum) maxsum = sum ;
    printf ("%dn", maxsum);

} 

What is the value printed out when this program is executed?

A
9
B
8
C
7
D
6
       Programming       C-Programming       GATE 2007-IT
Question 124 Explanation: 
The algorithm is for finding the maximum sum of the monotonically increasing continuous sequence of positive numbers in the array. So, output will be 3+4 = 7.
Question 125

Consider the program below in a hypothetical language which allows global variable and a choice of call by reference or call by value methods of parameter passing.

int i ;
program main ()
{
    int j = 60;
    i = 50;
    call f(i,j);
    print i, j;
}
procedure f(x,y)
{           
    i = 100;
    x = 10;
    y = y + i ;
} 
Which one of the following options represents the correct output of the program for the two parameter passing mechanisms?

A
Call by value : i = 70, j = 10; Call by reference : i = 60, j = 70
B
Call by value : i = 50, j = 60; Call by reference : i = 50, j = 70
C
Call by value : i = 10, j = 70; Call by reference : i = 100, j = 60
D
Call by value : i = 100, j = 60; Call by reference : i = 10, j = 70
       Programming       Parameter-Passing       GATE 2007-IT
Question 125 Explanation: 
Call by value:
'i' is a global variable. Then in main( ) a local variable 'j' as integer declared, i.e., j=60 and global variable 'i' is initialized to 50 by i=50.
Now procedure f called and values of 'i' and 'j' are passed to it, i.e., in f(i, j)→f(x, y).
Content of memory location of 'i' (here 50) is copied to memory location of x (which is different from i) and content of memory location of 'j' (here 60) is copied to memory location of y. Then in f(x, y) i=100 changes the global i to 100, x=10 changes the local x from 50 to 10 and y=y+i means y=60+100=160. Now, when return back to main, i & j will be 100 & 60 respectively.
Call by reference:
Now procedure f called and passed reference of i and j to it, i.e., in f(i,j)→f(x,y). x and y are pointing to same memory location of i and j respectively. So i=100 changes the global i to 100 and x=10 means as well as global i=10 (as the i being passed is the global variable and x and i share the same address).
y=y+i means y=60+10=70 and this changes the value of j also to as j and y have the same addresses. Now when return to main, i and j will be 10 and 70.
Question 126

Consider the program below in a hypothetical programming language which allows global variables and a choice of static or dynamic scoping.

int i ;
program main ()
{
    i = 10;
    call f();
}

procedure f()
{   
    int i = 20;
    call g ();
}
procedure g ()
{   
    print i;
} 
Let x be the value printed under static scoping and y be the value printed under dynamic scoping. Then, x and y are

A
x = 10, y = 10
B
x = 20, y = 10
C
x = 10, y = 20
D
x = 20, y = 20
       Programming       Variable Binding       GATE 2007-IT
Question 126 Explanation: 
Since the value of x is based on static scoping, in the procedure g( ), print i will directly look into the global scope and find i=10 which was previously set by main( ) and since the value of y is based on dynamic scope, procedure g( ) will first look into the function which called it, i.e., procedure f( ) which has a local i=20, which will be taken and 20 will be printed.
Question 127

Early binding refers to a binding performed at compile time and late binding refers to a binding performed at execution time. Consider the following statements:
i. Static scope facilitates w1 bindings.
ii. Dynamic scope requires w2 bindings.
iii. Early bindings w3 execution efficiency.
iv. Late bindings w4 execution efficiency.
The right choices of wl, w2, w3 and w4 (in that order) are

A
Early, late, decrease, increase
B
Late, early, increase, decrease
C
Late, early, decrease, increase
D
Early, late, increase, decrease
       Programming       Variable Binding       GATE 2007-IT
Question 127 Explanation: 
Static scoping can do early binding (during compile time). Early binding increases efficiency.
Dynamic scoping requires late binding (during execution time).
Late binding decreases efficiency as this binding needs to be done at run time.
Question 128

Which one of the choices given below would be printed when the following program is executed?

#include 
struct test {
               int i;
               char *c;
}st[] = {5, "become", 4, "better", 6, "jungle", 8, "ancestor", 7, "brother"};
main ()
{ 
    struct test *p = st;
    p += 1;
    ++p -> c;
    printf("%s,", p++ -> c);
    printf("%c,", *++p -> c);
    printf("%d,", p[0].i);
    printf("%s n", p -> c);
}
A
jungle, n, 8, ncestor
B
etter, u, 6, ungle
C
cetter, k, 6, jungle
D
etter, u, 8, ncestor
       Programming       Programming       GATE 2006-IT
Question 128 Explanation: 
Lets take the part of program,
Line 1 - main ( )
Line 2 - {
Line 3 - struct test *p = st;
Line 4 - p += 1;
Line 5 - ++p → c;
Line 6 - printf("%s", p++→ c);
Line 7 - printf("%c", +++p → c);
Line 8 - printf("%d", p[0].i);
Line 9 - printf("%s\n", p → c);
Line 10 - }
Now,
Line 3: Initially p is pointing to st, i.e., first element of st which is {5, "become"}
Line 4: Now p is pointing to {4, "better"}
Line 5: ++(p → c), since → has higher precedence, so p → c points to 'e' of "better".
Line 6: prints 'enter' and p now points to {6, "jungle"}
Line 7: ***(p → c), since → has higher precedence. So, prints 'u'.
Line 8: p → i, which is 6 so prints '6'.
Line 9: prints 'ungle' since p is pointing to 'u'.
So, output is "enter, u, 6, ungle".
Question 129
Which one of the choices given below would be printed when the following program is executed?
#include 
void swap (int *x, int *y)
{
    static int *temp;
    temp = x;
    x = y;
    y = temp;
}
void printab ()
{
    static int i, a = -3, b = -6;
    i = 0;
    while (i <= 4)
    {
        if ((i++)%2 == 1) continue;
        a = a + i;
        b = b + i;
    }
    swap (&a, &b);
    printf("a =  %d, b = %d\n", a, b);
}
main()
{
    printab();
    printab();
}
A
a = 0, b = 3
a = 0, b = 3
B
a = 3, b = 0
a = 12, b = 9
C
a = 3, b = 6
a = 3, b = 6
D
a = 6, b = 3
a = 15, b = 12
       Programming       Programming       GATE 2006-IT
Question 129 Explanation: 
First of all, the swap function just swaps the pointers inside the function and has no effect on the variable being passed.
Inside print 'a' and 'b' are added to odd integers from 1 to 5, i.e., 1+3+5=9. So, in first call to print ab,
a = -3+9 = 6
b = -6+9 = 3
Static variable have one memory throughout the program run (initialized during program start) and they keep their values across function calls. So during second call to print ab,
a = 6+9 = 15
b = 3+9 = 12
Question 130

Which one of the choices given below would be printed when the following program is executed?

#include 
int a1[] = {6, 7, 8, 18, 34, 67};
int a2[] = {23, 56, 28, 29};
int a3[] = {-12, 27, -31};
int *x[] = {a1, a2, a3};
void print(int *a[])
{
            printf("%d,", a[0][2]);
            printf("%d,", *a[2]);
            printf("%d,", *++a[0]);
            printf("%d,", *(++a)[0]);
            printf("%d/n", a[-1][+1]);
}
main()
{
             print(x);
}
A
8, -12, 7, 23, 8
B
8, 8, 7, 23, 7
C
-12, -12, 27, -31, 23
D
-12, -12, 27, -31, 56
       Programming       Programming       GATE 2006-IT
Question 130 Explanation: 
1) a[0][2] = *(*(a+0)+2)
It returns the value of 3rd element in a1.
First printf print 8.
2) *a[2] = *(*(a+2))
It returns the value of 1st element in a3.
Second printf print -12.
3) *++a[0] = *(++(*(a+0)))
a[0] is pointing to 1st element in a1.
++a[0] - after preincrement performed, now a[0] is pointing to 2nd element in a1.
*++a[0] return the value of 2nd element in a1.
Third printf print 7.
4) *(++a)[0]
++a - after preincrement is performed 'a' is pointing to a2.
(++a)[0] is pointing to 1st element in a2.
*(++a)[0] returns the value of 1st element in a2.
Fourth printf print 23.
5) a[-1][+1] = *(*(a-1)+1)
(a-1) is pointing to a1.
*(a-1) is pointing to the 2nd element in a1, because in 3rd printf already a1 was incremented by 1.
*(a-1)+1 is pointing 3rd element in a1.
*(*(a-1)+1) returns the value of 3rd element in a1, i.e., 8.
Question 131

The following function computes the value of mCn correctly for all legal values m and n (m≥1,n≥0 and m>n)

 int func(int m, int n)
{
    if (E) return 1;
    else return(func(m - 1, n) + func(m - 1, n - 1));
}

In the above function, which of the following is the correct expression for E?

A
(n == 0) || (m == 1)
B
(n == 0) && (m == 1)
C
(n == 0) || (m == n)
D
(n == 0) && (m == n)
       Programming       Programming       GATE 2006-IT
Question 131 Explanation: 
We know that,
mC0 = 1
nCn = 1
Question 132

Match the following concepts and their best possible descriptions.

    Concept:
    (i) overloading
    (ii) friend
    (iii) constructor
    (iv) protected
    (v) this
    (vi) inheritance
    Descriptions:
    A. allows to define a class to have a properties of another class
    B. defining a set of similar functions
    C. used in dereferncing
    D. used to given a non - member function access to the private parts of body
    E. a function which is automatically called when object is created
    F. allows a derived class to have access to the private parts of the base
    G. a pointer to the object associated with the current functions
    H. used to obtain persistence
A
(i) - B, (ii) - D, (iii) - E, (iv) - F, (v) - G, (vi) - A
B
(i) - C, (ii) - A, (iii) - E, (iv) - D, (v) - H, (vi) - F
C
(i) - C, (ii) - F, (iii) - H, (iv) - A, (v) - G, (vi) - D
D
(i) - B, (ii) - E, (iii) - C, (iv) - F, (v) - G, (vi) - H
       Programming       Match-the-Following       GATE 2006-IT
Question 132 Explanation: 
Note: Out of syllabus.
Question 133

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.

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++]]–
       Programming       Programming       GATE 2005-IT
Question 133 Explanation: 
A: Increments the count by 1 at each index that is equal to the ASCII value of the alphabet, it is pointing at.
B: Decrements the count by 1 at each index that is equal to the ASCII value of the alphabet it is pointing at. Also it increments the loop counter for next iteration.
If one string is permutation of other, there would have been equal increments and decrements at each index of array, and so count should contain zero at each index, that is what the loop checks at last and if any non-zero elements is found, it returns 0 indicating that strings are not anagram to each other.
Question 134

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?

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
2, 1, 4, 3, 6, 5, 7
C
1, 3, 2, 5, 4, 7, 6
D
2, 3, 4, 5, 6, 7, 1
       Programming       Programming       GATE 2005-IT
Question 134 Explanation: 
It is nothing but a pairwise swapping of the linked list.
Question 135

What is the output printed by the following program?

#include
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
       Programming       Programming       GATE 2005-IT
Question 135 Explanation: 

Hence, 9 is the answer.
Question 136

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.

A
a[j] – a[i] > S
B
a[j] – a[i] < S
C
a[i] – a[j] < S
D
a[i] – a[j] > S
       Programming       Programming       GATE 2005-IT
Question 136 Explanation: 
For some 'i' if we find that difference of (A[j] - A[i] < S) we increment 'j' to make this difference wider so that it becomes equal to S.
If at times difference becomes greater than S we know that it won't reduce further for same 'i' and so we increment the 'i'.
Question 137

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

1. a[i] ≥ b [i] => c[2i] ≥ a [i]
2. a[i] ≥ b [i] => c[2i] ≥ b [i]
3. a[i] ≥ b [i] => c[2i] ≤ a [i]
4. a[i] ≥ b [i] => c[2i] ≤ b [i] 
Which of the following is TRUE?

A
only I and II
B
only I and IV
C
only II and III
D
only III and IV
       Programming       Sorting       GATE 2005-IT
Question 137 Explanation: 
a[i] ≥ b[i]
Since both 'a' and 'b' are sorted in the beginning, there are 'i' elements than or equal to a[i] and similarly 'i' elements smaller than or equal to b[i]. So, a[i] ≥ b[i] means there are 2i elements smaller than or equal to a[i] and hence in the merged array, a[i] will come after these 2i elements. So, c[2i] ≤ a[i].
Similarly, a[i] ≥ b[i] says for b that, there are not more than 2i elements smaller than b[i] in the sorted array. So, b[i] ≤ c[2i].
So, option (C) is correct.
Question 138

Let x be an integer which can take a value of 0 or 1. The statement if(x = =0) x = 1; else x = 0; is equivalent to which one of the following?

A
x = 1 + x;
B
x = 1 - x;
C
x = x - 1;
D
x = 1 % x;
       Programming       Programming       GATE 2004-IT
Question 138 Explanation: 
x = 1 - x
For x = 0, it gives 1.
For x = 1, it gives 0.
Question 139

A program attempts to generate as many permutations as possible of the string, 'abcd' by pushing the characters a, b, c, d in the same order onto a stack, but it may pop off the top character at any time. Which one of the following strings CANNOT be generated using this program?

A
abcd
B
dcba
C
abad
D
cabd
       Programming       Programming       GATE 2004-IT
Question 139 Explanation: 
A) push 'a' and pop 'a', push 'b' and pop 'b', push 'c' and pop 'c', and finally push 'd' and pop 'd'. Sequence of popped elements will come to abcd.
B) First push abcd, and after that pop one by one. Sequence of popped elements will come to dcba.
C) push abc, and after that pop one by one. Sequence of popped elements will come to cba. Now push 'd' and pop 'd', final sequence comes to cbad.
D) This sequence is not possible because 'a' cannot be popped before 'b' anyhow.
Question 140

What is the output of the following program?

#include <stdio.h>
int funcf (int x);
int funcg (int y);

main()
{
    int x = 5, y = 10, count;
    for (count = 1; count <= 2; ++count)
    {
        y += funcf(x) + funcg(x);
        printf ("%d ", y);
    }
}

funcf(int x)
{
    int y;
    y = funcg(x);
    return (y);
}

funcg(int x)
{
    static int y = 10;
    y += 1;
    return (y+x);
}
A
43 80
B
42 74
C
33 37
D
32 32
       Programming       Programming       GATE 2004-IT
Question 140 Explanation: 
In first iteration:
In first case of funcf, which in turn calls funcg, y becomes 11 and it returns 5+11 = 16.
In second call of funcg, y becomes 12 and it returns 5+12 = 17.
So, in main y is incremented by 16+17 = 33 to become 10+33 = 43.
In second iteration:
y will be incremented by 18+19 = 37 to give 43+37 = 80.
Question 141

Consider the following C program which is supposed to compute the transpose of a given 4 x 4 matrix M. Note that, there is an X in the program which indicates some missing statements. Choose the correct option to replace X in the program.

#include<stdio.h>
#define ROW 4
#define COL 4
int M[ROW][COL] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
main()
{
    int i, j, t;
    for (i = 0; i < 4; ++i)
    {
        X
    }
    for (1 = 0; i < 4; ++i)
        for (j = 0; j < 4; ++j)
            printf ("%d", M[i][j]);
}
A
for(j = 0; j < 4; ++j){
t = M[i][j];
M[i][j] = M[j][i];
M[j][i] = t;
}
B
for(j = 0; j < 4; ++j){
M[i][j] = t;
t = M[j][i];
M[j][i] = M[i][j];
}
C
for(j = i; j < 4; ++j){
t = M[i][j];
M[i][j] = M[j][i];
M[j][i] = t;
}
D
for(j = i; j < 4; ++j){
M[i][j] = t;
t = M[j][i];
M[j][i] = M[i][j];
}
       Programming       Programming       GATE 2004-IT
Question 141 Explanation: 
To compute transpose 'j' needs to be started with 'i'. So, A and B are wrong.
In (D) , given statements is wrong as temporary variable needs to be assigned some value and not vice-versa.
Question 142

Choose the correct option to fill the ?1 and ?2 so that the program prints an input string in reverse order. Assume that the input string is terminated by a new line character.

#include 
void wrt_it (void);
int main (void)
{
    printf("Enter Text"); 
    printf ("n");
    wrt_ it();
    printf ("n");
    return 0;
}
void wrt_it (void)
{
    int c;
    if (?1)
        wrt_it();
    ?2
} 
A
?1 is getchar() ! = ‘\n’
?2 is getchar(c);
B
?1 is (c = getchar()); ! = ‘\n’
?2 is getchar(c);
C
?1 is c! = ‘\n’
?2 is putchar(c);
D
?1 is (c = getchar()) ! = ‘\n’
?2 is putchar(c);
       Programming       Programming       GATE 2004-IT
Question 142 Explanation: 
getchar( ) = reads a single character at a time from the stdin.
putchar( ) = writes a character specified by the argument to stdout.
As getchar( ) and putchar( ), both are needed to read the string and prints its reverse and only option (D) contains both the function. (D) is the answer.
Now coming to the code, wrt_id(void) is calling itself recursively. When \n is encountered, putchar( ) gets executed and prints the last character and then the function returns to its previous call and prints last 2nd character and so on.
Question 143

Consider the following C program:

#include <stdio.h>
typedef struct 
{
    char *a;
    char *b;
} t;
void f1(t s);
void f2(t *p);
main()
{
    static t s = {"A", "B"};
    printf ("%s %sn", s.a, s.b);
    f1(s);
    printf ("%s %sn", s.a, s.b);
    f2(&s);
}
void f1(t s)
{
    s.a = "U";
    s.b = "V";
    printf ("%s %sn", s.a, s.b);
    return;
}
void f2(t *p)
{
    p -> a  = "V";
    p -> b = "W";
    printf("%s %sn", p -> a, p -> b);
    return;
} 
What is the output generated by the program?

A
AB
UV
VW
VW
B
AB
UV
AB
VW
C
AB
UV
UV
VW
D
AB
UV
VW
UV
       Programming       Programming       GATE 2004-IT
Question 143 Explanation: 
→ First print AB.
→ f1 is call by value. The changes applicable only for local from f1. UV is printed.
→ Back in main( ), AB is printed.
→ Then in f2, VW is printed.
Hence, answer is (B).
Question 144
Consider the following C++ program Assuming the required header files are already included, the above program:
A
results in a compilation error
B
print 123
C
print 111
D
print 322
       Programming       Operator       ISRO-2018
Question 144 Explanation: 
Solution: A but official key given solution D
→ It gives compilation error because declaration of “intc” is wrong.
→ q+=b(a(q)) and r+=a(c(r)) will result compilation error.
Question 145
An array A consists of n integers in locations A[0], A[1] ….A[n-1]. It is required to shift the elements of the array cyclically to the left by k places, where 1 <= k <= (n-1). An incomplete algorithm for doing this in linear time, without using another array is given below. Complete the algorithm by filling in the blanks. Assume alt the variables are suitably declared.
A
i > min; j!= (n+i)mod n; A[j + k]; temp; i + 1 ;
B
i < min; j!= (n+i)mod n; A[j + k]; temp; i + 1;
C
i > min; j!= (n+i+k)mod n; A[(j + k)]; temp; i + 1;
D
i < min; j!= (n+i-k)mod n; A[(j + k)mod n]; temp; i + 1;
       Programming       Arrays       ISRO-2018
Question 145 Explanation: 
This question need presence of mind.
Step-1: Observe all options, 4 options they are given 4th and 5th blank is temp and i+1.
So, they given clue that, 4th and 5th options must be temp and i+1.
Step-2: Based on the 4th and 5th options, we can guess that 1st blank is i → Suppose if we are considering i>min then the control goes out of the while loop in the initial case when i=0 and min=n. So, 1st blank should be i Step-3: According to 1st blank, we can eliminate A and C options.
Step-4: Assume 2nd blank is correct, we are considering j!= (n+i) mod n this condition in while loop.
→ The meaning of the condition is “j becomes equal to (n+i)mod n then control goes out of the while loop.”
Step-5: The condition (n+i)mod n=i and j is always equal to i because we are assigning the value of i to j in the code segment line 3.
Step-6: based on these constraint we can say that 4th option is correct.
Reason: The control never enters the 2nd while loop. Sometimes it will enter the 2nd while loop, when we shift the numbers. It means total K places left.
Question 146
Consider the following C function
A
Call swap (a, b)
B
Call swap (&a, &b)
C
swap(a, b) cannot be used as it does not return any value
D
swap(a, b) cannot be used as the parameters passed by value
       Programming       Functions       ISRO-2017 May
Question 146 Explanation: 
Question 147
What does the following C-statement declare? int (*f) (int*);
A
A function that takes an integer pointer as an 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 an argument and returns an integer
D
A function that takes an integer pointer as an argument and returns a function pointer
       Programming       Declaration       ISRO-2017 May
Question 147 Explanation: 
→ int (*f) (int*); f is a pointer to a function that takes an integer pointer as an argument and returns an integer
→ int (*p)(char *a); p ia a pointer to a function that takes an argument as a pointer to a character and returns an integer.
Question 148
What will be the output of the following C code?
A
10 11 12 13 14
B
10 10 10 10 10
C
0 1 2 3 4
D
Compilation error
       Programming       Control Flow       ISRO-2017 May
Question 148 Explanation: 
Step-1: We are initialized i=0 in for loop. It means condition true because it is less than 5.
Step-2: Inside the for loop we are assigning again I value is 10 and printing value i.
Iteration-1: We are printing value 10 then increment by 1
Iteration-2: We are clearing previous value and assigning value 10. Printing value is 10;
Iteration-5: We are clearing previous value and assigning value 10. Printing value is 10
Step-3: output is 1010101010
Question 149
What does the following program do when the input is unsigned 16-bit integer?
A
It prints all even bits from num
B
It prints all odd bits from num
C
It prints binary equivalent of num
D
None of the above
       Programming       Control Flow       ISRO-2017 May
Question 149 Explanation: 
Step-1: Take n value initially 14(any number we can take but we are taken 14)
Step-2: 14<16
Step-3: It will print 00000000 00001110
Question 150
What is the output of the following program?
A
20 10 10
B
20 10 20
C
20 20 20
D
10 10 10
       Programming       Functions       ISRO-2017 May
Question 150 Explanation: 
Step-1: Every program starts execution from main() function.
Step-2: By default tmp value 20 will print initially.
Step-3: It calls fun() then it will print 10
Step-4: Again we are in main() function and printing value 20. Actually, the static value will return because its scope is a lifetime. But we are given tmp value as global. So, it prints 20 instead of 10.
Question 151
We use malloc and calloc for
A
Dynamic memory allocation
B
Static memory allocation
C
Both dynamic and static memory allocation
D
None of the above
       Programming       Calloc-Malloc       ISRO-2017 May
Question 151 Explanation: 
C -Dynamic memory allocation refers to performing manual memory management for dynamic memory allocation in the C programming language via a group of functions in the C standard library, namely
1. Malloc
2. Realloc
3. Calloc
4. Free.
Question 152
The complexity of the program is
A
O(log n)
B
O(n2)
C
O(n2 log n)
D
O(n log n)
       Programming       Control Flow       ISRO-2017 December
Question 152 Explanation: 
Question 153
What is the output of the following C program? #include<stdio.h> #define SQR(x) (x*x) int main() { int a; int b=4; a=SQR(b+2); printf("%d\n",a); return 0; }
A
14
B
36
C
18
D
20
       Programming       Macros       ISRO CS 2014
Question 153 Explanation: 
In the question, SQR is macro which is preprocessor statement in c language.
Here macro takes one parameter also.
A macro is a fragment of code that is given a name. You can use that fragment of code in your program by using the name. For example,
#define SQR(x) (x*x)
Here, when we use SQR(x) in our program, it's replaced with (x*x)
The movement program control execute the macro, it will replace SQR(b+2) by (b+2*b+2)
The expression (b+2*b+2) consists of addition and multiplication operators.
Between two operators multiplication operator has highest priority later addition .
So the expression evaluation steps are as follows
a = (b + 2*b + 2)
=(4+2*4+2)// first multiplication
=(4+8+2) // addition equal priority , so it will evaluate left to right
=(12+2)
=14
Question 154
Which of the following is true with respect to Reference?
A
A reference can never be NULL
B
A reference needs an explicit dereferencing mechanism
C
A reference can be reassigned after it is established
D
A reference and pointer are synonymous
       Programming       Pointers       ISRO CS 2014
Question 154 Explanation: 
In the C++ programming language, a reference is a simple reference data type that is less powerful but safer than the pointer type inherited from C. A reference is a general concept datatype, with pointers and C++ references being specific reference data type implementations.
We can assign NULL to pointers where as we can’t assign NULL to references.
We can re-assign pointers as many as number of times where a reference can never be re-assigned once it is established.
Question 155

What is the output of the following ‘C’ program ? (Assuming little - endian representation of multi-byte data in which Least Significant Byte (LSB) is stored at the lowest memory address.)

#include <stdio.h>
#include <stdlib.h>
/* Assume short int occupies two bytes of storage */ 
int main () 
{ 
       union saving 
       { 
           short int one; 
           char two[2]; 
       }; 
       union saving m; 
       m.two [0] = 5; 
       m.two [1] = 2; 
       printf("%d, %d, %d\n", m.two [0], m.two [1], m.one); 
}/* end of main */ 
A
5, 2, 1282
B
5, 2, 52
C
5, 2, 25
D
5, 2, 517
       Programming       C-Programming       UGC-NET CS 2018 JUNE Paper-2
Question 155 Explanation: 
• m.two[0] holds the value 5 and m.two[1] holds the value 2. So, it will print 5 and 2 values.
• Size of the short integer is 2 bytes. Saving is union variable, we will access one variable at time and only one memory location is shared among all the members. So, the two values 5 and 2 (two bytes of the data) will store in little endian format in the variable m.one.
• Endianness is the sequential order in which bytes are arranged into larger numerical values when stored in memory or when transmitted over digital links.
• In big-endian format, whenever addressing memory or sending/storing words bytewise, the most significant byte—the byte containing the most significant bit—is stored first (has the lowest address) or sent first, then the following bytes are stored or sent in decreasing significance order.
• Little-endian format reverses this order: the sequence addresses/sends/stores the least significant byte first (lowest address) and the most significant byte last (highest address).
• First 5 will store in the lowest address and 2 will store next highest address.
• So the binary representation 5 and 2 in little endian format is 00000010 00000101.
The binary number of the above is 517.
Question 156
Which of the following is the correct order of evaluation for the below expression?
z=x+y*z/4%2-1
A
*/%+-=
B
=*/%+-
C
/*%-+=
D
*%/-+=
       Programming       Operator       Nielit Scientist-B IT 4-12-2016
Question 156 Explanation: 
Here, *,/,% are having same priority. So, it executes follows first come first serve or left to write. +,- are having same priority. So, it executes follows first come first serve or left to write. = having least priority. It evaluates right to left.
Question 157
What is the meaning of following declaration?
int(*P[7])();
A
P is pointer to function
B
P is pointer to such function which return type is array
C
P is array of pointer to function
D
P is pointer to array of function
       Programming       Pointers       Nielit Scientist-B IT 4-12-2016
Question 157 Explanation: 
int *ptr[7]; --This is an array of 7 int* pointers, a pointer to an array of 7 ints
int (*ptr)[7]; --This is a pointer to an array of 7 int
int(*P[7])(); --P is array of pointer to function
int(*P)() ; --​ P is pointer to function
Question 158
The keyboard used to transfer control from a function back to the calling function is:
A
Switch
B
Go to
C
go back
D
Retun
       Programming       Functions       Nielit Scientist-B IT 4-12-2016
Question 158 Explanation: 
● The return statement terminates the execution of a function and it returns the control to the calling function.
● The execution resumes in the calling function at a point immediately following the call.
Question 159
Let A be a square matrix of size nxn. consider the following program. What is the expected output?
C=100
for i=1 to n do
for j=1 to n do
{
 Temp=A[i][j]+C
 A[i][j]=A[j][i]
 A[j][i]=Temp-C
}
for i=1 to n do
for j=1 to n do
 output(A[i][j]);
A
The matrix A itself
B
Transpose of matrix A
C
Adding 100 to the upper diagonal elements and subtracting 100 from diagonal elements of A
D
None of the option
       Programming       Arrays       Nielit Scientist-B CS 22-07-2017
Question 159 Explanation: 
Question 160
An external variable
A
is globally accessible by all functions
B
has a declaration "extern" associated with it when declared within a function
C
will be initialized to 0 if not initialized
D
All of these
       Programming       Storage-Classes       Nielit Scientist-C 2016 march
Question 160 Explanation: 
An external variable can be accessed by all the functions in all the modules of a program. It is a global variable. For a function to be able to use the variable, a declaration or the definition of the external variable must lie before the function definition in the source code. Or there must be a declaration of the variable, with the keyword extern, inside the function.
Question 161
What will be the value of x and y after execution of the following statement (C language)
n=5;
x=n++;
y=-x;
A
5,-4
B
6,-5
C
6,-6
D
5,-5
       Programming       Operator       Nielit Scientist-C 2016 march
Question 161 Explanation: 
Given statements are n=5, x=n++ and y=-x.
N++ is post increment statement, so first “n” will store into variable into “x” and later “n” value is incremented.
X value becomes 5 and y value become -5.
Question 162
In C programming language, if the first and the second operands of operator + are of types int and float, respectively, the result be of type
A
int
B
float
C
char
D
long int
       Programming       Data-Type       Nielit Scientist-C 2016 march
Question 162 Explanation: 
Expressions don’t have a type. Expressions can result in a value which has a type.
The rules for implicit type casting are as follows:
Integer Promotion: All types below int, like char and short are converted to int.
If still types other than int remain, following rules are executed by order
● If long double exists, all are converted to long double.
● If double exists, all are converted to double.
● If float exists, all are converted to float, and so on.
Question 163
For x and y are variables as declared below double x=0.005, y=-0.01; what is the value of ceil(x+y), where is a function to compute ceiling of a number?
A
1
B
0
C
0.005
D
0.5
       Programming       Data-Type       Nielit Scientist-C 2016 march
Question 163 Explanation: 
x+y = 0.005-0.01 =-0.005
Description
CEIL(x) rounds the number x up.
Examples
CEIL(1.3) equals 2
CEIL(-1.6) equals -1
Question 164
To sort many large objects or structures, it would be most efficient to place
A
them in an array and sort the array
B
pointers to them in an array and sort the array
C
them in a linked list and sort the linked list
D
references to them in an array and sort the array
       Programming       Structure       Nielit Scientist-C 2016 march
Question 164 Explanation: 
● Pointers will point to large objects or structures.
● By using pointers we will easily access the large objects or structures with the help the addresses pointing to them.
● If you made any changes to the elements in the array, it automatically reflect as these are pointed by the pointers
Question 165
If initialization is a part of declaration of a structure, then storage class can be
A
automatic
B
register
C
static
D
anything
       Programming       Structure       Nielit Scientist-C 2016 march
Question 165 Explanation: 
Storage class specifiers available in C programming language include 'auto', 'register', 'static' and 'extern'.Depending upon the developer requirement , the storage class is anything.
Question 166

Consider the following pseudo-code fragment, where m is a non-negative integer that has been initialized:

     p = 0;
     k = 0;
     while(k < m)
           p = p + 2k;
           k = k + 1;
     end while

Which of the following is a loop invariant for the while statement?

(Note: a loop variant for a while statement is an assertion that is true each time guard is evaluated during the execution of the while statement).

Options:
A
p = 2k - 1 and 0≤k
B
p = 2k+1 - 1 and 0≤k
C
p = 2k - 1 and 0≤k≤m
D
p = 2k+1 - 1 and 0≤k≤m
       Programming       programming       UGC-NET CS 2018 DEC Paper-2
Question 166 Explanation: 
For k=0, P = 0+20 = 1
k=1, P = 1+21 = 3
k=2, P = 3+22 = 7
k=3, P = 7+23 = 15
Only the option-3 satisfied to the loop variant.
Ex: m=2, The loop will execute for 3 times for k value is 0,1 and 2.
Then options-3 gives P=1, P=3 and P=7 for the k values 0,1 and respectively.
Question 167
What is the correct way to round off x, a float. to an int value?
A
y=(int)(x+0.5)
B
y=int(x+0.5)
C
y=(int)x+0.5
D
y=(int)(int) x+0.5)
       Programming       Type-Casting       Nielit Scientist-B CS 2016 march
Question 167 Explanation: 
Rounding off a value means replacing it by a nearest value that is approximately equal or smaller or greater to the given number.
y = (int)(x + 0.5); here x is any float value. To round off, we have to typecast the value of x by using (int)
Example:
#include
int main ()
{
float x = 3.6;
int y = (int)(x + 0.5);
printf ("Result = %d\n", y );
return 0;
}
Output:
Result = 4.
Question 168
What error would the following function given on compilation?
f(int a, int b)
{
int a;
a=20;
return a;
}
A
Missing parenthesis is return statement
B
Function should be defined as int f(int a, int b)
C
Redeclaration of a
D
None of these
       Programming       Compilation       Nielit Scientist-B CS 2016 march
Question 168 Explanation: 
We are already declared variable name ‘a’ in function. Again we are declared inside the function. So, the compiler will raise a error “Redeclaration of a”
Question 169
Prior to using a pointer variable it should be
A
declared
B
initialized
C
both declared and initialized
D
none of these
       Programming       Pointers       Nielit Scientist-B CS 2016 march
Question 169 Explanation: 
● In the programming, Before using any variable we should declare that variable.If require means initialize the variable.
● Pointer is also one variable
● So before using a pointer variable it should be both declared and initialized.
Question 170
Output of the following loop is for(putchar('c');putchar('a');putchar('r')) putchar('t');
A
a syntax error
B
cartrt
C
catrat
D
catratratratrat...
       Programming       Control Flow       Nielit Scientist-B CS 2016 march
Question 170 Explanation: 
Syntax of ‘for loop’
for(Initialization; Condition; value modification/updation)
As per the above question,
→ Initialization part given by putchar('c)
→ Condition part check by putchar('a')
→ Value modification/updation part given by putchar('r')
→ Inside the for loop we are given putchar('t’)
→ The sequence of the for loop first initialization, second condition, executing inside body of for loop and value modification.
So, it prints catratratratrat...
Question 171
If space occupied by two strings s1 and s2 in 'C' are respectively m and n, then space occupied by string obtained by concatenating s1 and s2 is always
A
less than m+n
B
equal to m+n
C
greater than m+n
D
none of these
       Programming       Strings       Nielit Scientist-B CS 2016 march
Question 171 Explanation: 
If space occupied by two strings s1 and s2 in 'C' are respectively m and n, then space occupied by string obtained by concatenating s1 and s2 is always less than m+n
Question 172

Consider the following method :

int f(int m, int n, boolean x, boolean y)
{
     int res=0;
     if(m<0) {res=n-m;}
     else if(x || y) {
                             res= -1;
                             if( n==m) { res =1; }
     }
     else {res=n; }
  return res;
} /*end of f */

If P is the minimum number of tests to achieve full statement coverage for f() and Q is the minimum number of tests to achieve full branch coverage for f(), then (P,Q) =

A
(3,4)
B
(3,2)
C
(2,3)
D
(4,3)
       Programming       Programming       UGC-NET CS 2018 DEC Paper-2
Question 172 Explanation: 
→ Code coverage is a measure which describes the degree of which the source code of the program has been tested.
→ Statement coverage is a white box test design technique which involves execution of all the executable statements in the source code at least once. It is used to calculate and measure the number of statements in the source code which can be executed given the requirements.
→ Branch coverage is a testing method, which aims to ensure that each one of the possible branch from each decision point is executed at least once and thereby ensuring that all reachable code is executed.
→ In the branch coverage, every outcome from a code module is tested. For example, if the outcomes are binary, you need to test both True and False outcomes.
Question 173

What will be output if you will compile and execute the following C code?

void main()

{

char c=125;

c=c+10;

printf("%d",c);

}
A
135
B
115
C
-121
D
-8
       Programming       Compilation       Nielit Scientist-B CS 4-12-2016
Question 173 Explanation: 
As we know any data type shows cyclic properties
In our example the data type is char data type , so if you will increase or decrease the char
variables beyond its maximum or minimum value respectively it will repeat same value
according to following cyclic order
So,
125+1= 126
125+2= 127
125+3=-128
125+4=-127
125+5=-126
125+6=-125
125+7=-124
125+8=-123
125+9=-122
125+10=-121
Question 174

What will be output if you will compile and execute the following C code?

void main()

{

printf("%d",sizeof(5.2));
}
A
4
B
8
C
2
D
16
       Programming       Compilation       Nielit Scientist-B CS 4-12-2016
Question 174 Explanation: 
Size of is a special operator will return number of bytes of data types. By default system will take integer data type,if we are not specifying any data type. Total size is 4 bytes.
Question 175
Consider the following function definition.
void greet (int n)
{
if (n>0)
{
printf("hello");
greet(n-1);
}
printf("world");
}
If you run greet(n) for some non-negative integer n, what would it print?
A
n times “hello”, followed by n + 1 times “world”
B
n times “hello”, followed by n times “world”
C
n times “helloworld”
D
n + 1 times “helloworld”
E
n times “helloworld”, followed by “world”
       Programming       Functions       TIFR PHD CS & SS 2018
Question 176
What will be the output of the following ‘C’ code ?
main( )
{
int x=128;
printf (“\n%d”, 1 + x++);
}
A
128
B
129
C
130
D
131
       Programming       Programming       UGC NET CS 2014 Dec-Paper-2
Question 176 Explanation: 
In this program we are using post increment. Post increment will send the value before updating the value.
printf(“\n%d”, 1 + x++); /* x=128 */
Here, 1+128=129
Question 177
Output of following program
#include
int main()
{
int i=5;
printf("%d%d%d", i++,i++,i++);
return 0;
}
A
765
B
567
C
777
D
compile dependent
       Programming       Control Flow       Nielit Scientist-B IT 22-07-2017
Question 177 Explanation: 
● Multiple increment or decrement of same variable in one expression or one statement is compiler dependent.
● The output will depend upon the way the compiler developed.
Question 178

Which of the following numerical values is NOT a valid constant in C language?

A
12345L
B
018CDF
C
9.3e12
D
0XBCF
       Programming       Data-Type       JT(IT) 2018 PART-B Computer Science
Question 178 Explanation: 
→ 12345L integer long is valid integer
→ 018CDF starts with 0 means octal number but actually we are given decimal and hexa numbers. So it is not a valid constant.
→ 9.3e12 float number
→ 0XBCF is hexa number. Valid constant.
Question 179
Output of following program?
#include
void dynamic(int s,..)
{
printf("%d",s);
}
int main()
{
dynamic(2,4,6,8);
dynamic(3,6,9);
return 0;
}
A
23
B
compile error
C
43
D
32
       Programming       Functions       Nielit Scientist-B IT 22-07-2017
Question 179 Explanation: 
● The latest compiler giving compilation error ​ “error: expected declaration specifiers or ‘...’ before ‘.’ toke​ n“
● Old compiler may support that syntax, in that syntax only first argument is defined which consists of remainings arguments but not defined.
● For the function call dynamic(2,4,6,8), first argument 2 is printed.
● For the function call dynamic(3,6,9);first argument 3 is printed.
Question 180
Output of following program?
#include
int main()
{
int *ptr;
int x;
ptr=&x;
*ptr=0;
printf("x=%d\n",x);
printf("*ptr=%d\n",*ptr);
*ptr+=5;
printf("x=%d\n",x);
printf("*ptr=%d\n",*ptr);
(*ptr)++;
printf(x=%d\n",x);
printf("*ptr=%d\n",*ptr);
return 0;
}
A
x=0
*ptr=0
x=5
*ptr=5
x=6
*ptr=6
B
x=garbage value
*ptr=0
x=garbage value
*ptr=5
x=garbage value
*ptr=6
C
x=0
*ptr=0
x=5
*ptr=5
x=garbage value
*ptr=garbage value
D
x=0
*ptr=0
x=0
*ptr=0
x=0
*ptr=0
       Programming       Pointers       Nielit Scientist-B IT 22-07-2017
Question 180 Explanation: 
● ptr=&x; // Address of x variable will store in to pointer “ptr” or pointer “ptr” will point to “x”
● *ptr=0; // storing value “0” in the memory location.
● printf("x=%d\n",x); // “0” will be printed
● printf("*ptr=%d\n",*ptr); // “0” will be printed because , ptr will point to variable “x”
● *ptr+=5; // *ptr+=5; means *ptr=*ptr+5 which is nothing but value 5 will store into memory locaton
● printf("x=%d\n",x); // 5 will be printed
● printf("*ptr=%d\n",*ptr); //5 will be printed.
● (*ptr)++; // (*ptr) means 5 and it is incremented by 1 so the updated value is “6”
● printf(x=%d\n",x); // “6” will be printed
● printf("*ptr=%d\n",*ptr);// “6” will be printed
Question 181
Assume that float takes 4 bytes, predict the output of following program.
#include
int main()
{
float arr[5]={12.5,10.0,13.5,90.5,0.5};
float *ptr1=&arr[0];
float *ptr2=ptr1+3;
printf("%f",*ptr2);
printf("%d",ptr2-ptr1);
return 0;
}
A
90.500000 3
B
90.500000 12
C
10.000000 12
D
0.500000 3
       Programming       Pointers       Nielit Scientist-B IT 22-07-2017
Question 181 Explanation: 
● float *ptr1=&arr[0]; // ptr1 will point to first element of the array.
● float *ptr2=ptr1+3; // ptr2 will point to fourth element of the array
● printf("%f",*ptr2); // It will display fourth element value which is 90.500000
● printf("%d",ptr2-ptr1); // Here both pointer will point to same array . The subtraction operation gives the number of elements between the addresses.
Question 182
Assume that size of an integer is 32 bit. What is the output of following ANSI C program?
#include
struct st
{
int x;
static int y;
};
int main()
{
printf(%d",sizeof(struct st));
return 0;
}
A
4
B
8
C
compile error
D
runtime error
       Programming       Structure       Nielit Scientist-B IT 22-07-2017
Question 182 Explanation: 
● It will be compile error-​ “error: expected specifier-qualifier-list before ‘static’ static int y;”
● Static variables are allocated memory in data segment, not stack segment.
● Static variable isn't allowed in struct because C requires the whole structure elements to be placed "together". To withdraw a element value from a structure is counted by the offset of the element from the beginning address of the structure.
Question 183
Consider the following C declaration
Struct
{
short s[5];
Union
{
float y;
long z;
}u;
}t;
Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes respectively. The memory requirement for variable t ignoring alignment considerations, is
A
22 bytes
B
14 bytes
C
18 bytes
D
10 bytes
       Programming       Structure       Nielit Scientist-B IT 22-07-2017
Question 183 Explanation: 
Union
{
float y;
long z;
}u;
● The sizeof union is 8 bytes (maximum size of two variables sizes 4 and 8)
● The size of structure is sum of short size(array of 5 elements) is 5x2=10 and union size is 8.
● So the total size is 18.
Question 184
#include
struct st
{
int x;
struct st next;
};
int main()
{
struct st temp;
temp.x=10;
temp.next=temp;
printf("%d",temp.next,x);
return 0;
}
A
Compile error
B
10
C
Runtime Error
D
Garbage value
       Programming       Structure       Nielit Scientist-B IT 22-07-2017
Question 184 Explanation: 
● We can’t declare structure member of own type with in the structure.
● But we can declare pointer structure member with in same structure which is called self referential structure.
● The above code gives compile error ​ “ ​ main.c:5:11: error: field ‘next’ has incomplete type struct st next”
Question 185
cross product is a
A
Unary operator
B
ternary operator
C
binary Operator
D
Not an operator
       Programming       Operator       Nielit Scientist-B IT 22-07-2017
Question 185 Explanation: 
● The cross product of two tables A x B builds a huge virtual table by pairing every row of A with every row of B.
● This operator requires two tables so it binary operator.
Question 186
What will be the output of following?
main()
{
static int a=3;
printf("%d",a--);
if(a)
main();
}
A
3
B
3 2 1
C
3 3 3
D
Program will fall in continuous loop and print 3
       Programming       Storage-Classes       Nielit Scientific Assistance IT 15-10-2017
Question 186 Explanation: 
The variable is static variable, the value is retained during multiple function calls. Initial value is 3
“A--” is post decrement so it will print “3”
if(2) condition is true and main() function will call again , Here the “a” value is 2.
“A--” is post decrement so it will print “2”
if(1) condition is true and main() function will call again Here the “a” value is 1.
“A--” is post decrement so it will print “1”
if(0) condition is false it won’t call main() function
Question 187
The following program fragment prints
int i=5;
do
{
putchar(i+100);
printf("%d",i--);
}
while(i);
A
i5h4g3f2el
B
14h3g2f1e0
C
An error message
D
None of the above
       Programming       Control Flow       Nielit Scientific Assistance IT 15-10-2017
Question 187 Explanation: 
Here, i=5 and putchar(i+100) it means actually putchar(5+100) ⇒ putchar(105);
It will print the ASCII equivalent of 105 which is lower case ' i '. The printf statement prints the current value of i. i.e. 5 and then decrements it. So, h4 will be printed in the next pass. This continues until ' i ' becomes 0, at which point the loop gets terminated.
Question 188

Consider the following algorithm:

Algorithm Anand(n)
{
          sum=0;
          For i=1 to n do
          {
                 For j=1 to i do
                 {
                        sum=sum+i;
                 }
           }
}

What will be the output of this algorithm for n=10?

A
370
B
385
C
380
D
55
       Programming       Control Flow       JT(IT) 2018 PART-B Computer Science
Question 188 Explanation: 

Step-1: if i=1, j is also will execute 1 time because it is purely dependent to the variable i.
Sep-2: The sum variable is perform addition how many time jth loop executes with the difference of i value.
Question 189

In C language ______ is a process in which a function calls itself repeatedly until some specified condition has been satisfied

A
Infinite loop
B
Call by value
C
Call by reference
D
Recursion
       Programming       Functions       JT(IT) 2018 PART-B Computer Science
Question 189 Explanation: 
Recursion is a process in which a function calls itself repeatedly until some specified condition has been satisfied.
Question 190
Consider the following declaration
int a, *b=&a, **c=&b;
a=4;
**c=5;
If the statement
b=(int *)**c
is appended to the above program fragment then
A
Value of b becomes 5
B
value of b will be the address of c
C
value of b is unaffected
D
none of these
       Programming       Pointers       Nielit Scientific Assistance IT 15-10-2017
Question 190 Explanation: 
In the given program fragment, three variables are there
Ordinary variable -a // value will be stored
Pointer variable -b // address of variable will be stored
Pointer to pointer variable(double pointer) -c // address of pointer variable will stored.
a=4 means storing/assigning value to “a”.
**c means value at(value at(c)) =value at(value at(&b)) (c holds address of pointer “b”)
=value at(&a) (b holds the address of “a”)
Memory location of variable “a”, value 5 is
stored/assigned into the variable.
Given statement is b=(int *)**c. So the value of b becomes 5.
Question 191

What is the return value of the C library function fmod(d1,d2), where d1 and d2 are integer numbers?

A
It returns the remainder of d2/d1, with the same sign as d1
B
It returns the remainder of d2/d1, with the same sign as d2
C
It returns the remainder of d1/d2, with the same sign as d1
D
It returns the remainder of d1/d2, with the same sign as d2
       Programming       Control Flow       JT(IT) 2018 PART-B Computer Science
Question 191 Explanation: 
Mod operations: fmod(d1,d2)
Take d1 = 10 and d2 = 20
d1/d2 = 10/20 = 10
So, option C is correct.
Question 192
Consider the following code segment in C++. How many times the for loop will be repeated?
int main()
{
int f=1;
for(;f;)
cout<<”f=”<<f++<<”\n”;
Return 0;
}
A
10 times
B
Not even once
C
Repeated forever
D
Only once
       Programming       Control Flow       KVS 22-12-2018 Part-B
Question 192 Explanation: 
There is no termination condition for the loop and value “f” incremented every time. So it will execute infinite number of times.
Question 193
Consider the following code segment:
int x=22,y=15;
x=(x>y)?(x+y):(x-y);
What will be the value of x after the code is executed?
A
22
B
37
C
7
D
37 and 7
       Programming       Operator       KVS 22-12-2018 Part-B
Question 193 Explanation: 
The condition 22>15 is true so it will execute 22+15 which is 37
Question 194
In the context of while loop do while loop in C++, which of the following is not true?
A
Both the loops are repetitive in nature
B
Boh are conditional loops
C
Both will be executed at least once
D
Both are terminated when the condition become false
       Programming       Control Flow       KVS 22-12-2018 Part-B
Question 194 Explanation: 
Do-while will execute at least one time while loop will execute minimum of zero times.
Question 195
Consider the code segment written below in C++:
if (count<10) //if#1
if((count%4)==2) //if#2
count<<”condition:white\n”;
else //(indentation is wrong)
count<<”condition is:tan\n”;
There are 2 if statements and one else. To which if, the else statement belong?
A
It belongs to if#1
B
It belongs to if#2
C
It belongs to both the if statements
D
It is independent
       Programming       if-else       KVS 22-12-2018 Part-B
Question 195 Explanation: 
→ The else statement belongs its immediate previous if statement.
→ If there are no braces ({}) following the if statement then only the next immediate statement belongs to the if statement. The same thing is true for else and else-if clause
Question 196
The following program fragment prints
int i=5;
do
{
putchar(i+100);
printf("%d",i--);
}while(i);
A
i5h4g3f2el
B
14h3g2f1e0
C
An error message
D
None of the above
       Programming       Control Flow       Nielit Scientific Assistance CS 15-10-2017
Question 196 Explanation: 
Step-1: putchar(105) will print the ASCII equivalent of 105 is ' i '.
Step-2: The printf statement prints the current value of i=5 because we are given post decrement.
Step-3: The same process will perform until it fail the condition.
Question 197

Which of the following ‘C’ language operators has the right to left associativity?

A
Relational operators
B
Conditional operators
C
Logical AND and OR operators
D
Arithmetic multiply and divide operators
       Programming       Operator       JT(IT) 2018 PART-B Computer Science
Question 197 Explanation: 
Logical AND and OR operators are having right to left associativity.
Question 198
What will be the value of C, in C=x++ + ++x + ++x + x, if x=10?
A
48
B
45
C
46
D
49
       Programming       Operator       KVS DEC-2013
Question 198 Explanation: 
→ Incrementing the same variable multiple times with in the same expression is abnormal behaviour. Multiple compiler gives different outputs.
→ The initial value of “x” is 10 and it is pre-incremented two times and later addition will be performed from left to right.
→ While performing the addition the variable “x” value is 12 and we adding four “x” variables so answer is 48 (output is based upon the Gcc compiler)
Question 199
Consider the following code segment
if(Y<0)
{
X=-X;
Y=-Y;
}
Z=0;
while(Y>0)
{
Z=Z+X;
Y=Y-1;
}
Assume that X,Y and Z are integer variables, and that X and Y have be initialized. Which of the following best describes what this code segment does?
A
Sets Z to be the product X*Y
B
Sets Z to be the sum X+Y
C
Sets Z to be the absolute value of Y
D
Sets Z to be the value of Y
       Programming       Control Flow       KVS DEC-2017
Question 199 Explanation: 
Assume X=3 and Y=3
So, it satisfying condition while(Y>0)
Iteration-1: while(3>0)
Z=0+3⇒ Z=3
Y=3-1⇒ Y=2
Iteration-2: while(2>0)
Z=3+3=6
Y=2-1=1
Iteration-3:while(1>0)
Z=6+3
Y=1-1=0
Iteration-4 while(0>0) fails.
So,It Sets Z to be the product X*Y=3*3=9
Question 200
In structured programming, a program is decomposed into modules. Coupling and Cohesion describe the characteristics of modules. A good decomposition should attempt to
A
Minimize coupling and minimize cohesion
B
Maximize coupling and minimize cohesion
C
Minimize coupling and maximize cohesion
D
Maximize coupling and maximize cohesion
       Programming       Coupling-and-Cohesion       KVS DEC-2017
Question 200 Explanation: 
→ In order to maximize cohesion, make sure you are always able to summarize the purpose of a single module in a single phrase.
→ If it turns out to be impossible to capture the purpose of a module into a single discriminative phrase, then that's a smell.
→ At the other hand, don't go totally overboard by making everything a separate module.
→ It will have a dramatic effect on the number of dependencies between modules, and therefore hurt you in terms of coupling.
→ One of the tools that might help you organizing your dependencies is the Dependency Structure Matrix.
Question 201

Which of the following method is used for repetitive in which each action is started in terms of a previous result:

A
Recursion
B
Iteration
C
Looping
D
Structures
       Programming       Recursion       JT(IT) 2016 PART-B Computer Science
Question 201 Explanation: 
→ Recursion is the process of repeating items in a self-similar way. In programming languages, if a program allows you to call a function inside the same function, then it is called a recursive call of the function.
Question 202
In C++, which of the following statements correctly returns the memory from the dynamic array pointer PP to the free store?
A
delete pp;
B
delete pp[]
C
delete []pp;
D
delete *pp;
       Programming       Arrays       KVS DEC-2017
Question 202 Explanation: 
The "free store is just another name of heap. It is an area of memory that is used for dynamic allocation of memory while the program is running(i.e., at run time). Dynamic allocation of memory from the heap allows us to create,use and dispose of objects as needed. It allows us to grow and shrink dynamic data structure(Eg:Linked list,tree,graphs) while the program executes. there is no distinction between the "free store" and the heap. they refer to the same thing.
Question 203
Assume X and Y are non zero positive integers. Consider the following pseudo code
fragment:
while X< >Y do
if X > Y then
X ← X-Y
else
Y← Y-X
endif
end while
print(X)
What is the code doing?
A
It computes the GCD of two numbers
B
It computes the LCM of two numbers
C
It finds the smallest of two numbers
D
It divides the largest number by the smaller
       Programming       Control Flow       KVS DEC-2017
Question 203 Explanation: 
Let X=3 and Y=5
1​ st​ pass : X=3 and Y=2
2​ nd​ pass : X=1 and Y=2
3​ rd​ pass : X=1 and Y=1
Write(X), which writes 1. Which is nothing but GCD of 3 & 5.
Question 204
A condition that is caused by run time error in a computer program is known as
A
Exception
B
Syntax error
C
Semantic error
D
Fault
       Programming       Compilation       KVS DEC-2017
Question 204 Explanation: 
● An exception is an abnormal or unprecedented event that occurs after the execution of a software program or application. It is a runtime error of an undesired result or event affecting normal program flow.
● An exception is also known as a fault.
Question 205
What is the following program segment doing?
main()
{
int d=1;
do
{
printf(“%d”\n”,d++);
}while(d<=9);
}
A
Adding 9 integers
B
Adding integers from 1 to 9
C
Displaying integers from 1 to 9
D
No output
       Programming       Control Flow       KVS 30-12-2018 Part B
Question 205 Explanation: 
The code consists of do-while loop in which action performs first and later condition checking.
In the printf() statement, d++ means first it will display d value and increment the d value later condition checking.So the integer values 1 to 9 will be printed.
Question 206
What shall be the output of the following program in C++(using turbo C++)?
#include<iostream.h>
float answer;
main()
{
answer=⅓;
cout<<”The value of ⅓ is” <<answer,,”\n”;
return(0);
}
A
The value of ⅓ is 0
B
The value of ⅓ is 0.33
C
The value of ⅓ is 0.3333
D
The value of ⅓ is 1/3
       Programming       C++       KVS 30-12-2018 Part B
Question 206 Explanation: 
The expression answer=⅓ , which is integer divide by integer operation .
Modulus operation gives the quotient values when one number is divided by another number .
When 1 is divide by 3, the quotient is o
Question 207
What shall be the output of the following code segment in C++?
int main()
{
int x=0,i=4;
switch(i)
{
default:x+=5;
cout<<”x=<<x<<”\n”;
Case 4:x+=4;
cout<<”x=<<x<<”\n”;
Case 1:x+=1;
cout<<”x=<<x<<”\n”;
Case 2:x+=2;
cout<<”x=<<x<<”\n”;
Case 3:x+=3;
cout<<”x=<<x<<”\n”;
}
return 0;
}
A
x=4,x=10
B
x=4
C
x=10
D
x=9
       Programming       Switch-Case       KVS 30-12-2018 Part B
Question 207 Explanation: 
The output of the above program is x=4,x=5,x=7 and x=10 as there is no break statement is the switch case. From the above options the possible values are 4 and 10 only.
Question 208
Consider the following code segment in C++;
value=1;
result=(value++ *5)+(value++ *3)
What shall be the answer, after this code is executed?
A
result=11 or 13
B
result=16 or 19
C
result=21 or 16
D
result=19 or 21
       Programming       Operator       KVS 30-12-2018 Part B
Question 208 Explanation: 
→If the one variable incremented multiple time in single expression , it gives abnormal behaviour .
→Consider the following expression, result=(value++ *5)+(value++ *3), post increements operation will be performed in the expression.
→result=(value++ *5)+(value++ *3) First left side operand evaluates means (1*5+2*3)=11
→result=(value++ *5)+(value++ *3) First right side operand evaluates means (2*5+1*3)=13
Question 209
Data members which are static
A
Cannot be assigned a value
B
Can only be used in static functions
C
Cannot be defined in a union
D
Can be accessed outside the class
       Programming       Storage-Classes       KVS 30-12-2018 Part B
Question 209 Explanation: 
→When we declare a normal variable (data member) in a class, different copies of those data members create with the associated objects.
→In some cases when we need a common data member that should be same for all objects, we cannot do this using normal data members. To fulfill such cases, we need static data members.
→If you are calling a static data member within a member function, member function should be declared as static (i.e. a static member function can access the static data members)
Question 210
In VB, which of the following arithmetic operators has the highest level of precedence?
A
+ -
B
* /
C
^(exponentiation)
D
MOD
       Programming       Operator       KVS 30-12-2018 Part B
Question 210 Explanation: 
^(exponentiation) operator has highest precedence than arithmetic operators
Question 211
The following ‘C’ statement : int *f [ ] ( ); declares:
A
A function returning a pointer to an array of integers.
B
Array of functions returning pointers to integers.
C
A function returning an array of pointers to integers.
D
An illegal statement.
       Programming       Programming       UGC NET CS 2016 Aug- paper-2
Question 211 Explanation: 
int *f [ ] ( ); It declares array of functions returning pointers to integers.
Question 212
Given i = 0, j = 1, k = –1 x = 0.5, y = 0.0 What is the output of the following expression in C language ?
x * y < i + j || k
A
-1
B
0
C
1
D
2
       Programming       Programming       UGC NET CS 2016 July- paper-2
Question 212 Explanation: 
x * y < i + j || k
Step-1: Evaluate x * y because multiplication has more priority than remaining operators
x * y→ 0
Step-2: i + j is 1
Step-3: (x*y) < (i+j) is 1. Because relational operators only return 1(TRUE) or 0(FALSE).
Step-4: ((x*y) < (i+j)) || k is logical OR operator.
1 || -1 will returns 1.
Note: The precedence is ((x*y) < (i+j)) || k
Question 213
The following statement in ‘C’
int (*f())[ ];
declares
A
a function returning a pointer to an array of integers.
B
a function returning an array of pointers to integers.
C
array of functions returning pointers to integers.
D
an illegal statement.
       Programming       Pointers       UGC NET CS 2016 July- paper-2
Question 213 Explanation: 
int (*f())[ ] declare a function returning a pointer to an array of integers.
Question 214
What is the value returned by the function f given below when n = 100?
int f (int n)
{
if (n = = 0) then return n;
else return n + f(n-2);
}
A
2550
B
2556
C
5220
D
5520
       Programming       Programming       UGC NET CS 2016 July- paper-2
Question 214 Explanation: 
Given n=100
Step-1: int f(100)
{ if (100 = = 0) then return 100; /*false*/
else return 100 + f(100-2); /* return 198 */
}
Step-2: int f(98)
{ if (98 = = 0) then return 98; /*false*/
else return 98 + f(96); /* return 194 */
}
Step-3: int f(96)
{ if (96 = = 0) then return 96; /*false*/
else return 96 + f(94); /* return 190 */
}
;
;
Step-final:
int f(0)
{ if (0 = = 0) then return 0; /*TRUE*/
else return 0 + f(0); /* FALSE */
}
Actual process:
The above series is nothing but sum of Arithmetic Progression(A.P)
= 2+4+6+8+ ... +98+100
= n(n+1)
/* It is nothing but sum of even numbers upto 'n' */
= 50*51
= 2550
Question 215
Consider the following program :
#include
main( )
{
int i, inp;
float x, term=1, sum=0;
scanf(“%d %f ”, &inp, &x);
for(i=1; i<=inp; i++)
{
term = term * x/i;
sum = sum + term ;
}
printf(“Result = %f\n”, sum);
}
The program computes the sum of which of the following series?
A
x + x​ 2​ /2 + x​ 3​ /3 + x​ 4​ /4 +...
B
x + x​ 2​ /2! + x​ 3​ /3! + x​ 4​ /4! +...
C
1 + x​ 2​ /2 + x​ 3​ /3 + x​ 4​ /4 +...
D
1 + x​ 2​ /2! + x​ 3​ /3! + x​ 4​ /4! +...
       Programming       Programming       UGC NET CS 2015 Dec- paper-2
Question 215 Explanation: 
In this problem, we have to find series of evaluation.
Let x=5, inp=5
Iteration-1:
for(i=1; i<=inp; i++)
/* condition true 1<=5 */
{
term = term * x/i;
/* (1*5)/1=5. Here, 5 nothing but ‘x’ */
sum = sum + term ; /* 0+5=5 */
}
Iteration-2: Here, ‘i’ becomes 2.
for(i=2; i<=inp; i++)
/* condition true 2<=5 */
{
term = term * x/i;
/* (5*5)/2 is nothing but x​ 2​ /i */
sum = sum + term ; /* 5+12=17 */
}
;;;
;;;
Iteration-5: Here, ‘i’ becomes 5.
for(i=5; i<=inp; i++)
/* condition true 5<=5 */
{
term = term * x/i;
/* (625*5)/5! is nothing but x​ 5​ /i! */
sum = sum + term ;
}
So, Option-B is correct answer.
Question 216
The __________ transfers the executable image of a C++ program from hard disk to main memory.
A
Compiler
B
Linker
C
Debugger
D
Loader
       Programming       Programming-in-c++       UGC NET CS 2015 Dec- paper-2
Question 216 Explanation: 
→ The loader transfers the executable image of a C++ program from hard disk to main memory.
→ Loader is the program of the operating system which loads the executable from the disk into the primary memory(RAM) for execution. It allocates the memory space to the executable module in main memory and then transfers control to the beginning instruction of the program .
→ Loading a program involves reading the contents of the executable file containing the program instructions into memory, and then carrying out other required preparatory tasks to prepare the executable for running. Once loading is complete, the operating system starts the program by passing control to the loaded program code.
Question 217
What is the output of the following program?
(Assume that the appropriate preprocessor directives are included and there is no syntax error)
main( )
{
char S[ ] = "ABCDEFGH";
printf ("%C", *(&S[3]));
printf ("%s", S+4);
printf ("%u", S);
/* Base address of S is 1000 */
}
A
ABCDEFGH1000
B
CDEFGH1000
C
DDEFGHH1000
D
DEFGH1000
       Programming       Arrays       UGC NET CS 2015 Jun- paper-2
Question 217 Explanation: 
Step-1: String is stored in appropriate location is

Step-2: printf ("%C", *(&S[3]));
This statement will print character ‘D’
(&S[3]) → Will print address of index 3
*(&S[3]) → will print value in index 3. The value is nothing but ‘D’.
Step-3: printf ("%s", S+4); /* will print characters ‘EFGH’ */
Because previous S value index position is 3. Now we are performing +4 operations. It will print EFGH. we are given escape sequence is String.
Step-4: printf ("%u", S); → It will print address of S. The base address given as S is 1000.
Question 218
Given that x = 7.5, j = -1.0, n = 1.0, m = 2.0
the value of --x + j == x>n>=m is:
A
0
B
1
C
2
D
3
       Programming       Operator       UGC NET CS 2015 Jun- paper-2
Question 218 Explanation: 
Step-1: Given data, x = 7.5, j = -1.0, n = 1.0, m = 2.0
given condition is --x + j == x > n >= m
(6.5 + (-1.0)) == ((6.5 > 1.0) >= 2.0)
Here, 6.5 is greater than 1.0. so, it will print TRUE value is 1
Step-2: (5.5 == (1 >= 2.0))
Here, 1 is less than 2.0. So, it will print FALSE value is 0
Step-3: 5.5 == 0
5.5 is not equal to 0. So, it will print FALSE value is 0.
Question 219
Suppose x and y are two Integer Variables having values 0x5AB6 and 0x61CD respectively. The result (in hex) of applying bitwise operator and to x and y will be :
A
0 x 5089
B
0 x 4084
C
0 x 78A4
D
0 x 3AD1
       Programming       Operator       UGC NET CS 2004 Dec-Paper-2
Question 219 Explanation: 
Given two integer numbers are 0x5AB6 and 0x61CD
Step-1: Convert hexadecimal numbers into binary number because we want to perform AND operation.
0x5AB6 equivalent into binary number is 0101 1010 1011 0110
0x61CD equivalent into binary number is 0110 0001 1100 1101
Step-2: Perform Bitwise AND operation
0101 1010 1011 0110
0110 0001 1100 1101
-----------------------------
0100 0000 1000 0100(Bitwise AND operation)
------------------------------
Step-3: Convert result into hexadecimal number.
0100 0000 1000 0100 equivalent into hexadecimal number is 0x4084
Question 220
Consider the following statements,
int i=4, j=3, k=0;
k= ++i- - -j + i++ - - - j +j++;
What will be the values of i, j and k after the statement.
A
7, 2, 8
B
5, 2, 10
C
6, 2, 8
D
4, 2, 8
       Programming       Operator       UGC NET CS 2004 Dec-Paper-2
Question 220 Explanation: 
Given values are i=4, j=3 and k=0
Step-1: k= ++i- --j + i++ - --j +j++;
k= 5 - 2 + 5 - 1 + 1
k= (5-2)+(5-1)+1
= 3 + 4 + 1
= 8
Step-2: The value of i=6,j=2 and k=8
Question 221
What is the value of the arithmetic expression (Written in C) 2*3/4-3/4*2
A
0
B
1
C
1.5
D
None of the above
       Programming       Operator       UGC NET CS 2004 Dec-Paper-2
Question 221 Explanation: 
Given expression is 2*3/4-3/4* 2
Step-1: In C language multiplication and division having higher priority than addition and subtraction.
Step-2: Evaluating procedure is ((2*3)/4)-((3⁄4)* 2)
= ((2*3)/4)-((3⁄4)* 2)
= (6/4)-((3⁄4)* 2)
= 1 - ((3⁄4)* 2)
= 1 - 0*2
= 1 - 0
= 1
Question 222
Non modifiable procedures are called
A
Serially useable procedures
B
Concurrent procedures
C
Reentrant procedures
D
Top down procedures
       Programming       Functions       UGC NET CS 2004 Dec-Paper-2
Question 222 Explanation: 
→ A computer program or subroutine is called reentrant if it can be interrupted in the middle of its execution and then safely be called again ("re-entered") before it’s previous invocation complete execution.
→ The interruption could be caused by an internal action such as a jump or call, or by an external action such as an interrupt or signal. The previous invocations may resume correct execution before the reentered invocation completes, unlike recursion, where the previous invocations may only resume correct execution once the reentered invocation completes.
Rules:
1. Reentrant code may not hold any static or global non-constant data.
2. Reentrant code may not modify itself.
3. Reentrant code may not call non-reentrant computer programs or routines.
Question 223
What is the output of the following C-program
main()
{
printf(''%d%d%d'', sizeof(3.14f), sizeof(3.14), sizeof(3.141));
}
A
4 4 4
B
4 8 10
C
8 4 8
D
8 8 8
E
None of the above
       Programming       Operator       UGC NET CS 2005 Dec-Paper-2
Question 223 Explanation: 
The sizeof operator will print number of bytes of a data type.
sizeof(3.14f) → It will consider as float data type. The float data type size is 4 bytes.
sizeof(3.14) → It will consider as double data type. The double data type size is 8 bytes.
sizeof(3.141) → It will consider as double data type. The double data type size is 8 bytes.
Output= 4 8 8
Note: The exact size of each of these 3 types depends on the C compiler implementation (or) platform
Question 224
The bitwise OR of 35 with 7 in C will be :
A
35
B
7
C
42
D
39
       Programming       Operator       UGC NET CS 2005 Dec-Paper-2
Question 224 Explanation: 
Step-1: First we have to convert into binary numbers
(35)​ 10​ = (​ 0010 0011​ ) ​ 2
(7)​ 10​ = (0000 0111)​ 2
Step-2: Perform OR operation on both binary numbers.
0010 0011
0000 0111
---------------
0010 0111
----------------
Step-3: Convert result into Decimal number
(0010 0111)​ 2​ = (39)​ 10
Question 225
​ What will be the value of i for the following expression : int i=11, i=3 ; i+=(f >3) ? i & 2:5 ;
A
2
B
5
C
13
D
12
       Programming       Operator       UGC NET CS 2005 Dec-Paper-2
Question 225 Explanation: 
Let assume f=11 and i=3
i=i+(11>3) ? 3&2 : 5
/* 11>3 condition true. So, it will perform 3&2
(3)10 → (11)2
(2)10 → (10)2
----
10 (AND)
----
(10)2 = (2)10
So, i=3+2
i=5
Note: Instead of ‘f’ they given ‘i’ value in question. Excluded for evaluation.
Question 226
Nonmodifiable procedures are called :
A
Serially usable procedure
B
Concurrent procedure
C
Reentrant procedure
D
Top down procedure
       Programming       Functions       UGC NET CS 2005 Dec-Paper-2
Question 226 Explanation: 
→ A computer program or subroutine is called reentrant if it can be interrupted in the middle of its execution and then safely be called again ("re-entered") before it’s previous invocation complete execution. → The interruption could be caused by an internal action such as a jump or call, or by an external action such as an interrupt or signal. The previous invocations may resume correct execution before the reentered invocation completes, unlike recursion, where the previous invocations may only resume correct execution once the reentered invocation completes.
Rules:
1. Reentrant code may not hold any static or global non-constant data.
2. Reentrant code may not modify itself.
3. Reentrant code may not call non-reentrant computer programs or routines.
Question 227
After 3 calls of the c function bug( ) below, the values of i and j will be :
int j=1;
bug( )
{
static int i=0; int j=0;
i++;
j++;
return (i);
}
A
i = 0, j = 0
B
i = 3, j = 3
C
i = 3, j = 0
D
i = 3, j = 1
       Programming       Storage-Classes       UGC NET CS 2005 june-paper-2
Question 227 Explanation: 
Step-1: Initially i=0 but given as static. The scope is lifetime.
Step-2: Call-1: i=1 and j=1
Call-2: i=2 and j=1 because ‘i’ is static ‘j’ is again become 0 when it starts new call.
Call-3: i=3 and j=1 because ‘i’ is static ‘j’ is again become 0 when it starts new call.
Note: A static ‘int’ variable remains in memory while the program is running.
Question 228
Find the output of the following “C” code :
main ( )
{
int x=20, y=35;
x= y++ + x++;
y= ++y + ++x;
printf (“%d, %d\n”, x,y);
}
A
55, 93
B
53, 97
C
56, 95
D
57, 94
E
56, 93
       Programming       Operator       UGC NET CS 2005 june-paper-2
Question 228 Explanation: 
Step-1: Here, we are using post increment for both x and y. In post increment the value assign first and update after assigning.
x= 35 + 20
y= 37 + 56 (In this statement, ‘y’ will become 36 before performing pre increment)
Step-2: Final x=56 and y=93
Note: They given wrong options. We are added correct option.
Excluded for evaluation.
Question 229
main( )
{
char *str = “abcde”;
printf (“%c”, *str);
printf (“%c”, *str++);
printf (“%c”, *(str++));
printf (“%s”, str);
}
The output of the above ‘C’ code will be :
A
a a c b c d e
B
a a c c c d e
C
a a b c d e
D
None of these
       Programming       Operator       UGC NET CS 2005 june-paper-2
Question 229 Explanation: 
The above program we are using post increment operators. In post increment the value assign first and update after assigning.
main( )
{
char *str = “abcde”;
printf (“%c”, *str); /* It returns character ‘a’ */
printf (“%c”, *str++); /* It returns character ‘a’ because it is used post increment*/
printf (“%c”, *(str++)); /* It returns character ‘b’ because the previous increment is update here and present also they given post increment, so it only returns ‘b’ */
printf (“%s”, str); /* It returns aabcde */
}
Question 230
When a function is recursively called, all automatic variables :
A
are initialized during each execution of the function
B
are retained from the last execution
C
are maintained in a stack
D
are ignored
       Programming       Functions       UGC NET CS 2006 Dec-paper-2
Question 230 Explanation: 
→ When a function is recursively called, all automatic variables are initialized during each execution of the function. → Automatic local variables primarily applies to recursive lexically-scoped languages. An automatic variable is a local variable which is allocated and deallocated automatically when program flow enters and leaves the variable's scope. The scope is the lexical context, particularly the function or block in which a variable is defined.
Question 231
Enumeration variables can be used in :
A
search statement like an integer variable
B
break statement
C
preprocessor commands
D
function statement
       Programming       Data-Type       UGC NET CS 2006 Dec-paper-2
Question 231 Explanation: 
→ Enumeration variables can be used in search statement like an integer variable.
→ The enumerator names are usually identifiers that behave as constants in the language. An enumerated type can be seen as a degenerate tagged union of unit type. A variable that has been declared as having an enumerated type can be assigned any of the enumerators as a value.
→ In ‘C’ language exposes the integer representation of enumeration values directly to the programmer. Integers and enum values can be mixed freely, and all arithmetic operations on enum values are permitted. It is even possible for an enum variable to hold an integer that does not represent any of the enumeration values.
Question 232
int arr[ ]={1, 2, 3, 4}
int count;
incr( )
{
return ++count;
}
main( )
{
arr[count++]=incr( );
printf(“arr[count]=%d\n”, arr[count]);
}
The value printed by the above program is ​ :
A
1
B
2
C
3
D
4
       Programming       Arrays       UGC NET CS 2006 Dec-paper-2
Question 232 Explanation: 
Step-1: Before printing the arr[count] value, the variable “count” is incremented twice then count =2
Step-2: arr[2] value is 3 , So, it will print the value “3”.
Method-2:
→ The function incr() is executed as it is first statement.
→ Count is global variable whose initial value is 0 ,the function definition increments the count value and returns value “1” to the main function.
→ Again the main function, the expression arr[count++] , here count variable operation is post increment so arr[1] will store the value “1”.
→ After that statement , count value becomes “2” as it is incremented in the previous statement (total two increments).
→ Before printing the arr[count] value, the variable “count” is incremented twice then count =2
→ arr[2] value is 3 , so it will print the value “3”.
Question 233
When one-dimensional character array of unspecified length is assigned an initial value :
A
an arbitrary character is automatically added to the end of the string
B
‘0’ is added to the end of the string
C
length of the string is added to the end of the string
D
‘end’ is added to the end of the string
       Programming       Arrays       UGC NET CS 2006 Dec-paper-2
Question 233 Explanation: 
→ String literals are stored in ‘C’ as an array of chars, terminated by a null byte. A null byte is a char having a value of exactly zero, noted as '\0'.
→ When one-dimensional character array of unspecified length is assigned an initial value ‘0’ is added to the end of the string.
Question 234
The declaration “unsigned u” indicates :
A
u is an unsigned character
B
u is an unsigned integer
C
u is a character
D
u is a string
       Programming       Data-Type       UGC NET CS 2006 Dec-paper-2
Question 234 Explanation: 
The declaration “unsigned u” indicates u is an unsigned integer.
Question 235
What is the output of the following program segment ?
main ( )
{
int count, digit=0;
count=1;
while(digit <=9)
{
printf(​"%d /n”" , ++count);
++digit;
}
}
A
10
B
9
C
12
D
11
       Programming       Control-Statement       UGC NET CS 2006 June-Paper-2
Question 235 Explanation: 
The digit starts with 0 and will run 9 more times. It means, the loop will run 10 runs. The count variable we are given pre increment. So, it increments before assigning values.
It prints the result is
2 /n 3 /n 4 /n 5 /n 6 /n 7 /n 8 /n 9 /n 10 /n 11
Question 236
A static variable is one :
A
Which cannot be initialized
B
Which is initialized once at the commencement of execution and cannot be changed at runtime
C
Which retains its value throughout the life of the program
D
Which is the same as an automatic variable but is placed at the head of a program
       Programming       Storage-Classes       UGC NET CS 2006 June-Paper-2
Question 236 Explanation: 
A static variable is one which retains its value throughout the life of the program. The static storage class instructs the compiler to keep a local variable in existence during the life-time of the program instead of creating and destroying it each time it comes into and goes out of scope.
Question 237
If the following loop is implemented
{
int num=0;
do
{
- - num;
printf (​ ”%d”​ , num);
num++;
} while (num >50)
}
A
the loop will run infinitely many times
B
the program will not enter the loop
C
there will be compilation error reported
D
a run time error will be reported
       Programming       Control-Statement       UGC NET CS 2006 June-Paper-2
Question 237 Explanation: 
It will run infinite number of times because the --num variable is keep on reducing amount and num++ variable is keep on increasing amount. So, it never violate condition.
Question 238
# define max(x, y) x=(x > y) ?x :y is a macro definition, which can find the maximum of two numbers x and y if :
A
x and y are both integers only
B
x and y are both declared as float only
C
x and y are both declared as double only
D
x and y are both integers, float or double
       Programming       Macros       UGC NET CS 2006 June-Paper-2
Question 238 Explanation: 
→ The C preprocessor is a macro preprocessor (allows you to define macros) that transforms your program before it is compiled.
→ A macro is a fragment of code that is given a name. You can use that fragment of code in your program by using the name. For example,
→ #define c 299792458 // speed of light
→ Here, when we use c in our program, it's replaced with 299792458.
→ From the given question, the x and y consists of any data type.
Question 239
The function sprintf( ) works like printf( ), but operates on:
A
Data in a file
B
stdrr
C
stdin
D
string
       Programming       Strings       UGC NET CS 2006 June-Paper-2
Question 239 Explanation: 
Syntax:
int sprintf ( char * str, const char * format, ... );
Composes a string with the same text that would be printed if format was used on printf, but instead of being printed, the content is stored as a C string in the buffer pointed by str.
Question 240
What does the following expression means ? char *(*(*a[N]) ( )) ( );
A
a pointer to a function returning array of n pointers to function returning character pointers.
B
a function return array of N pointers to functions returning pointers to characters
C
an array of n pointers to function returning pointers to characters
D
an array of n pointers to function returning pointers to functions returning pointers to characters.
       Programming       Programming       UGC NET CS 2014 Dec-Paper-2
Question 240 Explanation: 
char *(*(*a[N]) ( )) ( ); /* an array of n pointers to function returning pointers to functions returning pointers to characters */
Question 241
Consider an array A[20, 10], assume 4 words per memory cell and the base address of array A is 100. What is the address of A[11, 5] ? Assume row major storage.
A
560
B
565
C
570
D
575
       Programming       Arrays       UGC NET CS 2014 Dec-Paper-2
Question 241 Explanation: 
Here, Row major order generally follows offset formula to find address of the location.
Offset= (Row number * Total number of columns) + Column Number
Step-1: Add the Base address to calculate the effective address. Given matrix is A[20][10], Size of memory word is 4 bytes, address of the location to find A[11][5], Base address is 100.
Step-2: Offset = (11*10) + 5
= 115 (multiply with 4 words)
= 115*4
= 460
Step 3: Initial base address is 100
=Offset+base address
= 460 +100
= 560.
Question 242
Consider the following pseudo-code fragment, where m is a non-negative integer that has been initialized:
p=0;
k=0;
while(k < m)
        p = p + 2k;
        k=k+1;
end while
Which of the following is a loop invariant for the while statement?
(Note: a loop variant for a while statement is an assertion that is true each time guard is evaluated during the execution of the while statement).
A
p = 2 k − 1 and 0≤k < m
B
p = 2 k+1 − 1 and 0≤k < m
C
p = 2 k − 1 and 0≤k≤m
D
p = 2 k+1 − 1 and 0≤k≤m
       Programming       Control-Statement       UGC NET CS 2018-DEC Paper-2
Question 242 Explanation: 
For k=0, P=0+2​ 0​ =1
k=1, P=1+2​ 1​ =3
k=2,P=3+2​ 2​ =7
k=3,P=7+2​ 3​ =15
Only the option-3 satisfied to the loop variant.
Ex: m=2, The loop will execute for 3 times for k value is 0,1 and 2.
Then options-3 gives P=1,P=3 and P=7 for the k values 0,1 and respectively
Question 243
Consider the C/C++ function f() given below:
void f(char w [ ] )
{
int x = strlen(w); //length of a string
char c;
For (int i = 0; i < x; i++)
{
c = w[i];
w[i] = w[x - i - 1];
w[x - i - 1] = c;
}
}
Which of the following is the purpose of f() ?
A
It output the content of the array with the characters rearranged so they are no longer recognized a the words in the original phrase.
B
It output the contents of the array with the characters shifted over by one position.
C
It outputs the contents of the array in the original order.
D
It outputs the contents of the array in the reverse order.
       programming       Strings       UGC NET CS 2018-DEC Paper-2
Question 243 Explanation: 
It outputs the contents of the array in the original order because it swaps pairs of elements at locations (i and x - i - 1) twice .
Question 244
What does the following java function perform ? (Assume int occupies four bytes of storage)
Public static int f(int a)
{
//Pre-conditions : a>0 and no overflow/underflow occurs
int b=0;
for(int i=0; i<32; i++)
{
b=b <<1;
b= b | (a & 1);
a = a >>> 1; // This is a logical shift
}
Return b;
}
A
Return the int that represents the number of 0’s in the binary representation of integer a.
B
Return the int that represents the number of 1’s in the binary representation of integer a.
C
Return the int that has the reversed binary representation of integer a.
D
Return the int that has the binary representation of integer a.
       Programming       Programming       UGC NET CS 2018-DEC Paper-2
Question 244 Explanation: 
→ Consider the a value is 5 .
The initial value of b is 0 and b<<1 means b will get value of 2
b=b|(a&1) which means 2|(5&1) then b will get value “2”
a=a<<1 means value a will reduce to 3
→ Repeat the above procedure for 31 iterations .
→ Iteration-2: b=b<<1 then b is 4 and b=b|(a&1)= 4|(3&1) then b is 5 and a becomes 1
→ Iteration-3: b=b<<1 then b is 10 and b=b|(1&1)= 4|(3&1) then b is 11 and a becomes 0
→ And this procedure will repeat until “i” value is 32.
→ The final value is 11 (Number of 1’s in the result is 2) and the number of 1’s in the input 5 are 2.
Question 245
Consider the following recursive Java function f that takes two long arguments and returns a float value :
public static float f(long m, long n)
{
float result = (float) m / (float) n;
if (m < 0 || n < 0)
return 0⋅0f;
else
result += f(m*2, n*3);
result result;
}
Which of the following integers best approximates the value of f(2,3) ?
A
0
B
3
C
1
D
2
       Programming       Programming       UGC NET CS 2018-DEC Paper-2
Question 245 Explanation: 
public static float f(long m, long n)
{
float result = (float) m / (float) n;
if (m < 0 || n < 0)
return 0⋅0f;
else
result += f(m*2, n*3);
result result;
}
function call→ f(2,3)
→ result=2.0/3.0
=0.666
if condition is false, else will be executed result = 0.666+f(4,9) function call→ f(4,9)
→ result=4.0/9.0
=0.444
result=0.4444+f(8,27)
function call→ f(8,27)
→ result=8.0/27.0
=0.2962
result=0.2962+f(16,54)
function call→ f(16,81)
→ result=16.0/81.0
=0.1975
result=0.1975+f(32,243)
function call→ f(32,243)
→ result= 32.0/243.0
= 0.13168
result=0.13168+f(64,729)
and so on
f(128,2187),f(256,6561),f(512,19683),f(1024,59049),f(2048,177147)
result=0.6666+0.4444+0.2962+0.1975+0.13168+0.08779+0.0390+0.026+0.0173+0.0115
The best approximate value is sum of all the function call result values which is equal 2.
Question 246
Consider the following method :
int f(int m, int n, boolean x, boolean y)
{
int res=0;
if(m<0) {res=n-m;}
else if(x || y) {
res= -1;
if( n==m) { res =1; }
}
else {res=n; }
return res;
} /*end of f */
If P is the minimum number of tests to achieve full statement coverage for f() and Q is the minimum number of tests to achieve full branch coverage for f(), then (P,Q) =
A
(3,4)
B
(3,2)
C
(2,3)
D
(4,3)
       Programming       Programming       UGC NET CS 2018-DEC Paper-2
Question 246 Explanation: 
→ Code coverage is a measure which describes the degree of which the source code of the program has been tested
→ Statement coverage is a white box test design technique which involves execution of all the executable statements in the source code at least once. It is used to calculate and measure the number of statements in the source code which can be executed given the requirements.
→ Branch coverage is a testing method, which aims to ensure that each one of the possible branch from each decision point is executed at least once and thereby ensuring that all reachable code is executed.
→ In the branch coverage, every outcome from a code module is tested. For example, if the outcomes are binary, you need to test both True and False outcomes.
Question 247
Match the following :  
A
a-iii, b-iv, c-i, d-ii
B
a-iii, b-iv, c-ii, d-i
C
a-iv, b-iii, c-ii, d-i
D
a-iv, b-iii, c-i, d-ii
       Programming       Storage-Classes       UGC NET CS 2014 June-paper-2
Question 247 Explanation: 
Automatic storage class→ Value stored in memory and local to the block in which the variable is defined.
Register storage class → Value stored in CPU registers rather than main memory.
Static storage class → Value of the variable persists between different function calls.
External storage class → Scope of the variable is global.
Question 248
When we pass an array as an argument to a function, what actually gets passed ?
A
Address of the array
B
Values of the elements of the array
C
Base address of the array
D
Number of elements of the array
       Programming       Functions       UGC NET CS 2014 June-paper-2
Question 248 Explanation: 
When we pass an array as an argument to a function it actually gets passed base address of the array.
Question 249
While(87) printf(“computer”); The above C statement will
A
print “computer” 87 times
B
print “computer” 0 times
C
print “computer” 1 times
D
print “computer” infinite times
       Programming       Output-based       UGC NET CS 2014 June-paper-2
Question 249 Explanation: 
When we are giving any positive number in while loop. It considered into TRUE value.
So, printf(“computer”); will execute infinite number of times.
while(1) or while(87) are same. It consider like TRUE only.
Question 250
Which of the following is the correct value returned to the operating system upon the successful completion of a program ?
A
0
B
1
C
-1
D
Program do not return a value.
       Programming       Functions       UGC NET CS 2014 June-paper-2
Question 250 Explanation: 
The operating system will return 0 when it’s successfully execute a program.
Question 251
What is the size of the following Union ? Assume that the size of int = 2, size of float = 4, size of char = 1

     union tag {

     int a;

     float b;

     char c;

     };

A
2
B
4
C
1
D
7
       Programming       Structure       UGC NET CS 2013 Sep-paper-2
Question 251 Explanation: 
Union: The compiler allocates the memory by considering the size of the largest memory. So, size of union is equal to the size of largest member
union tag
{
int a; /* It takes only 2 bytes */
float b; /* It takes only 4 bytes */
char c; /* It takes only 1 bytes */
};
As per the definition of union will take 4 bytes of memory. Because float having highest size among all.
Question 252
Assume that x and y are non-zero positive integers. What does the following program segment perform ? while (x!=0) { if (x>y)     x = x-y;     else      y=y-x; printf(“%d”,x); }
A
Computes LCM of two numbers
B
Computes GCD of two numbers
C
Divides large number with small number
D
Subtracts smaller number from large number
       Programming       Control-Statement       UGC NET CS 2013 Sep-paper-2
Question 252 Explanation: 
Let X=3 and Y=5
1st pass : X=3 and Y=2
2nd pass : X=1 and Y=2
3rd pass : X=1 and Y=1
Write(X), which writes 1.
Which is nothing but GCD of 3 & 5.
Question 253
Consider the following program segment :

d=0;

for(i=1; i<31, ++i)

for(j=1; j<31, ++j)

for(k=1; k<31, ++k)

if ((i+j+k)%3)= = 0);

d = d + 1;

printf(“%d”, d);

The output will be

A
9000
B
3000
C
90
D
2700
       Programming       Control-Statement       UGC NET CS 2013 Sep-paper-2
Question 253 Explanation: 
Step1: Each for loop will execute 30 times, then total number of iterations are 30*30*30=27000,
But value “d” is incremented only factors of 3 only.
Step2: For the values i=1, j=1 then
k=1,4,7,10,13,16,19,22,25 and 28(10 times)
i=1 and j=2 then
k=3,6,9,12,15,18,21,24,27,and 30(10 times)
i=1 and j=3 then
K=2,5,8,11,14,17,20,23,26,29(10 times)
Then for i=1 value there will be 30*10 =300 times.
Finally for all “i” values from 1 to 30 is
= 300*30
= 9000
Question 254
What is the output of the following ‘C’ program ? (Assuming little - endian representation of multi-byte data in which Least Significant Byte (LSB) is stored at the lowest memory address.)
#include
#include
/* Assume short int occupies two bytes of storage */
int main ( )
{
union saving
{
short int one;
char two[2];
};
union saving m;
m.two [0] = 5;
m.two [1] = 2;
printf(’’%d, %d, %d\n”, m.two [0], m.two [1], m.one);
}/* end of main */
A
5, 2, 1282
B
5, 2, 52
C
5, 2, 25
D
5, 2, 517
       Programming       Structure       UGC NET CS 2018 JUNE Paper-2
Question 254 Explanation: 
● m.two[0] holds the value 5 and m.two[1] holds the value 2 So it will print 5 and 2 values.
● Size of the short integer is 2 bytes. Saving is union variable, we will access one variable at time and only one memory location is shared among all the members.So the two values 5 and 2 (two bytes of the data) will store in little endian format in the variable m.one.
● Endianness is the sequential order in which bytes are arranged into larger numerical values when stored in memory or when transmitted over digital links.
● In big-endian format, whenever addressing memory or sending/storing words bytewise, the most significant byte—the byte containing the most significant bit—is stored first (has the lowest address) or sent first, then the following bytes are stored or sent in decreasing significance order,
● Little-endian format reverses this order: the sequence addresses/sends/stores the least significant byte first (lowest address) and the most significant byte last (highest address).
● First 5 will store in the lowest address and 2 will store next highest address.
● So the binary representation 5 and 2 in little endian format is 00000010 00000101
The binary number of the above is 517
Question 255
Given below are three implementations of the swap( ) function in C++ :

Which of these would actually swap the contents of the two integer variables p and q ?
A
(a) only
B
(b) only
C
(c) only
D
(b) and (c) only
       Programming       Functions       UGC NET CS 2018 JUNE Paper-2
Question 255 Explanation: 
Module -(a) is call by value , so by using that code w can not swap the contents.
Module -(b) is call by reference , So the modification of content in the function reflects the changes in the main program. Swapping is done in the module -(b).
Module -(c) is passing addresses as parameters but in the functions definition , We are changing the addresses not the content So swapping of the values can’t be done.
Question 256
Which of the following statements is/are True ?
P : C programming language has a weak type system with static types.
Q : Java programming language has a strong type system with static types.
A
P only
B
Q only
C
Both P and Q
D
Neither P nor Q
       Programming       Storage-Classes       UGC NET CS 2018 JUNE Paper-2
Question 256 Explanation: 
→ A strongly typed language has stricter typing rules at compile time, which implies that errors and exceptions are more likely to happen during compilation. Most of these rules affect variable assignment, return values and function calling.
→ A weakly typed language has looser typing rules and may produce unpredictable results or may perform implicit type conversion at runtime
→ Java, C#, Ada and Pascal are sometimes said to be more strongly typed than C, a claim that is probably based on the fact that C supports more kinds of implicit conversions, and C also allows pointer values to be explicitly cast while Java and Pascal do not.
→ Java itself may be considered more strongly typed than Pascal as manners of evading the static type system in Java are controlled by the Java virtual machine's type system.
→ C# and VB.NET are similar to Java in that respect, though they allow disabling of dynamic type checking by explicitly putting code segments in an "unsafe context".
→ Pascal's type system has been described as "too strong", because the size of an array or string is part of its type, making some programming tasks very difficult
Question 257
Enumeration is a process of
A
Declaring a set of numbers
B
Sorting a list of strings
C
Assigning a legal values possible for a variable
D
Sequencing a list of operators
       Programming       Data-Type       UGC NET CS 2012 Dec-Paper-2
Question 257 Explanation: 
→ Enumeration is a data type consisting of a set of named values called elements, members, enumeral, or enumerators of the type.
→ Enumeration is a process of assigning a legal values possible for a variable
Question 258
What is the result of the following expression? (1 & 2) + (3 & 4)
A
1
B
3
C
2
D
0
       Programming       Operator       UGC NET CS 2012 Dec-Paper-2
Question 258 Explanation: 
Given statement, (1&2)+(3/4)
(1&2) means (1 AND 2)
(¾) means (3 divided by 4)
Step-1: First consider (1&2)

Question 259
What does the following declaration mean ?          int (*ptr) [10];
A
ptr is an array of pointers of 10 integers.
B
ptr is a pointer to an array of 10 integers.
C
ptr is an array of 10 integers.
D
none of the above.
       Programming       Arrays       UGC NET CS 2013 Dec-paper-2
Question 259 Explanation: 
int (*ptr) [10]; It means ‘ptr’ is a pointer to an array of 10 integers.
Question 260
Which of the following has compilation error in C ?
A
int n=32 ;
B
char ch=65 ;
C
float f=(float)3.2 ;
D
none of the above
       Programming       Compilation       UGC NET CS 2013 Dec-paper-2
Question 260 Explanation: 
Option-A: ‘n’ is a integer value and and value of ‘n’ is 32.
Option-B: ‘ch’ is a character variable and value of ‘ch’ is 65.
Option-C: ‘f’ is a floating point variable and it uses type casting.
Option-D is correct answer.
Question 261
The correct way to round off a floating number x to an integer value is
A
y = (int) (x + 0.5)
B
y = int (x + 0.5)
C
y = (int) x + 0.5
D
y = (int) ((int)x + 0.5)
       Programming       Type-Casting       UGC NET CS 2013 Dec-paper-2
Question 261 Explanation: 
Here, with the help of type casting method we can round off a floating number x to integer value.
→ Type casting is a way to convert a variable from one data type to another data type.
Question 262
_______ is often used to prove the correctness of a recursive function.
A
Diagonalization
B
Communitivity
C
Mathematical Induction
D
Matrix Multiplication
       Programming       Functions       UGC NET CS 2013 Dec-paper-2
Question 262 Explanation: 
→ Mathematical Induction is often used to prove the correctness of a recursive function.
→ Mathematical Induction is a special way of proving things. It has only 2 steps:
Step-1: Show it is TRUE for the first one
Step-2: Show that if any one is TRUE then the next one is true
Then all are true
Question 263
Which of the following metric does not depend on the programming language used ?
A
Line of code
B
Function count
C
Member of token
D
All of the above
       Programming       Properties       UGC NET CS 2012 June-Paper2
Question 263 Explanation: 
Function count does not depend on the programming language used. It only counts number of functional entries in the function.
Lines of code (LOC) is a software metric used to measure the size of a computer program by counting the number of lines in the text of the program's source code.
Question 264
printf(“%c”, 100);
A
prints 100
B
prints ASCII equivalent of 100
C
prints garbage
D
none of the above
       Programming       ASCII       UGC NET CS 2012 June-Paper2
Question 264 Explanation: 
printf(“%c”, 100); → It prints ASCII equivalent of 100.
→ It prints character ‘b’.
Question 265
X – = Y + 1 means
A
X = X – Y + 1
B
X = –X – Y – 1
C
X = –X + Y + 1
D
= X – Y – 1
       Programming       Operator       UGC NET CS 2011 Dec-Paper-2
Question 265 Explanation: 
In Programming languages like C,C++ and Java we can write X-=Y+1 into X=X-Y+1
Note: X*=Z+1 → X=X*Z+1
X/=Z+1 → X=X/Z+1
X+=Z+1 → X=X+Z+1
Question 266
From the point of view of the programmer, what are the major advantages of using a high-level language rather than internal machine code or assembly language ?
A
Program portability
B
Easy development
C
Efficiency
D
None of the above
       Programming       Programming-languages       UGC NET CS 2011 June-Paper-2
Question 266 Explanation: 
High-level language refers to the higher level of abstraction from machine language. Rather than dealing with registers, memory addresses and call stacks, high-level languages deal with variables, arrays, objects, complex arithmetic or boolean expressions, subroutines and functions, loops, threads, locks, and other abstract computer science concepts, with a focus on usability over optimal program efficiency.
Question 267
When the following code is executed what will be the value of x and y ? int x = 1, y = 0;      y = x++;
A
2,1
B
2,2
C
1,1
D
1,2
       Programming       Operator       UGC NET CS 2013 June-paper-2
Question 267 Explanation: 
Given post increment for x value. In post increment the value assign first and update after assigning.
So, x=2 and y=1
Question 268
How many values can be held by an array A(–1,m;1,m) ?
A
m
B
m2
C
m(m+1)
D
m(m+2)
       Programming       Arrays       UGC NET CS 2013 June-paper-2
Question 268 Explanation: 
int A[n] means "n" elements and index starts from 0 to n-1.
→ Similarly, int A[n][n] means both column and rows has "n" elements and total elements are n*n nothing but n2 elements.
In the given example ,an array A(-1,m;1,m)
→ In which rows indexes are -1,0,1,2, and so on up to m then total rows are "m+2".
→ columns consist of 1,2,3 and so on up to m then total elements in columns are "m".
Total elements are (m+2)*m
Question 269
What is the result of the expression (1&2)+(3/4) ?
A
1
B
2
C
3
D
0
       Programming       Operator       UGC NET CS 2013 June-paper-2
Question 269 Explanation: 
Given statement, (1&2)+(3/4)
(1&2) means (1 AND 2)
(¾) means (3 divided by 4)
Step-1: First consider (1&2)

Question 270
How many times the word ‘print’ shall be printed by the following program segment ?
for (i=1, i≤2,i++)
for (j=1,j≤2,j++)
for(k=1,k≤2,k++)
printf("print/n")
A
1
B
3
C
6
D
8
       Programming       Control-Statement       UGC NET CS 2013 June-paper-2
Question 270 Explanation: 
Iteration-1: In iteration-1 of ith loop will execute once and jth loop 2 times.
Each jth loop will execute kth loop 2 times.
Finally, iteration-1 will display 4 times of “print/n” word.
Iteration-2: In iteration-2 of ith loop will execute once and jth loop 2 times.
Each jth loop will execute kth loop 2 times.
Finally, iteration-2 will display 4 times of “print/n” word.
Above code segment will print 8 times.
Better understanding purpose given modified code segment:
#include
int main()
{
int i,j,k,jj=0,kk=0,ii=0;
for(i=1;i<=2;i++)
{
ii++;
for(j=1;j<=2;j++)
{
jj++;
for(k=1;k<=2;k++)
{
kk++;
printf("print/n");
}
}
}
printf("ii=%d \t jj=%d \t kk=%d",ii,jj,kk);
return 0;
}
Output:
print/n print/n print/n print/n print/n print/n print/n print/n
ii=2 jj=4 kk=8
Question 271
Consider the function
find (int x, int y)
{return ((x < y) ? 0 : (x - y)) ; }
Let a, b be two non-negative integers. The call find {a, find(a, b)} can be used to find the
A
maximum of a, b
B
positive difference of a, b
C
sum of a, b
D
minimum of a, b
       Programming       Functions       NIELIT Technical Assistant_2016_march
Question 272
How many of the following declarations are correct ?
int z = 7.0;
double void = 0.000;
short array [2] = {0, 1, 2};
char c = “\n”;
A
None
B
One is correct
C
Two are correct
D
All four are correct
       Programming       Data-Type       UGC NET CS 2010 Dec-Paper-2
Question 272 Explanation: 
int z = 7.0; → Incorrect. Given data type is integer but given floating point number. It is wrong declaration.
double void = 0.000; → Incorrect. void is a keyword but can’t use with variable declaration.
It always return null value.
short array [2] = {0, 1, 2}; → Correct. It is right format. We can declare static values here itself.
char c = “\n”; → Incorrect. It is character data type but given in double quotes. It should be single quote instead of double quote.
Question 273
Which one of the following will set the value of y to 5 if x has the value 3, but not otherwise ?
A
if (x = 3) y = 5
B
if x = = 3 (y = 5)
C
if (x = = 3); y = 5
D
if (x = = 3) y =5
       Programming       Operator       UGC NET CS 2010 Dec-Paper-2
Question 273 Explanation: 
Here, they given two conditions
1. x has the value of 3 and
2. y value should be 5
Step-1: Based on the conditions, option-A is wrong because they are assign the 3 value to x but x is equals to 3.
Step-2: Option-B they given x==3 and y=5 but we have to give parenthesis to x condition.
Step-3: Option-C they given syntax error by using ;
Step-4: Option-D is the correct representation to above 2 conditions.
Question 274
Which one of the following sentences is true ?
A
The body of a while loop is executed at least once.
B
The body of a do ... while loop is executed at least once.
C
The body of a do ... while loop is executed zero or more times.
D
A for loop can never be used in place of a while loop.
       Programming       Control-Statement       UGC NET CS 2010 Dec-Paper-2
Question 274 Explanation: 
Syntax: do
{
Statement-1;
Statement-2;
}while(condition)
Here, without checking condition, it enters into loop. It means it executes at least once irrespective of condition.
Question 275
The statement
printf(“%d”,10 ? 0 ? 5 : 1 : 12);
will print
A
10
B
0
C
12
D
1
       Programming       Operator       UGC NET CS 2010 June-Paper-2
Question 275 Explanation: 
We can write above statement into (10 ? (0 ? 5 : 1) : 12)
Step-1: (0 ? 5 : 1) → It will give result 1 because the condition is FALSE because given value is 0. If nonzero given in condition, it will print TRUE value.
Step-2: (10 ? 1 : 12) → Here, given condition is nonzero. So, it will print TRUE value. The TRUE value is 1.
Note: Ternary operators(?:) evaluation starts from innermost conditions first.
Question 276
What will be the output of the following c-code ?
void main ( )
{
char *P = "ayqm" ;
char c;
c = ++*p ;
printf ("%c", c);
}
A
a
B
c
C
b
D
q
       Programming       Operator       UGC NET CS 2010 June-Paper-2
Question 276 Explanation: 
Pointer "p" will point to the string "ayqm",
*p means the first character of the string which is "a"
++*p means an increment of "a" which is nothing but "b"
printf ("%c", c); means the character "b" will be printed as output.
Note: They given syntax error in program.
Question 277
Top-down design does not require