Programming
Question 2 
0, c  
0, a+2  
‘0’, ‘a+2’  
‘0’, ‘c’ 
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.
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 
Hi Bye Bye Hi  
Hi Bye Hi Bye  
Bye Hi Hi Bye  
Bye Hi Bye Hi 
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”.
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 
4  
5  
6  
40 
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.
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 
10230  
10231  
10232  
10233 
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=y1;
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
int count=0;
Count(x,y){
if(y!=1){
if(x!=1){
printf("*");
count = count +1;
Count(x/2,y);
}
else{
y=y1;
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 
compiler error as the return of malloc is not typecast approximately  
compiler error because the comparison should be made as x==NULL and not as shown  
compiles successfully but execution may result in dangling pointer  
compiles successfully but execution may result in memory leak 
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.
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 
53423122233445  
53423120112233  
53423122132435  
53423120213243 
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 
Return of 6 and 6 respectively.  
Infinite loop and abnormal termination respectively.  
Abnormal termination and infinite loop respectively.  
Both terminating abnormally. 
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(val1);
}
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.
{ 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(val1);
}
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 
3  
4  
5  
6 
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)=35=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_MAX2. 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.
{
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)=35=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_MAX2. 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 
23  
24  
25  
26 
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 
P→(ii),Q→(iv),R→(i),S→(iii)  
P→(ii),Q→(i),R→(iv) S→(iii)  
P→(ii),Q→(iv),R→(iii),S→(i)  
P→(iii),Q→(iv),R→(i),S→(ii) 
Question 11 Explanation:
Static char var; ⇾ A variable located in Data Section of memory
P→(ii),Q→(iv),R→(i),S→(iii)
P→(ii),Q→(iv),R→(i),S→(iii)
Question 12 
0, 0  
0, 1  
1, 0  
1, 1 
Question 12 Explanation:
printxy (int x, int y)
{
int *ptr;
x = 0;
ptr = &x;
y = *ptr;
*ptr = 1;
}
printxy (1, 1)
{
int *ptr;
x = 0;
ptr = &x;
y = *ptr;
*ptr = 1;
}
printxy (1, 1)
Question 13 
(q==r) && (r==0)  
(x>0) && (r== x) && (y>0)  
(q==0) && (r==x) && (y>0)  
(q==0) && (y>0) 
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).
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 
3  
4  
5  
6 
Question 14 Explanation:
Swap (&x, &y) exchanges the contents of x & y.
①⇒ 1st for i = 0 <= 4 a[0] < a[1] ≃ 3<5 so perform swapping
done=
①⇒ no swap (3, 1)
②⇾ perform swap (1, 4)
①⇒ perform swap (1, 6)
①⇒ perform swap (1, 2)
①⇒ (done is still 0)
for i = 5 >= 1 a[5] > a[4] ≃ 1>2 – false. So, no swapping to be done
②⇾ no swap (6, 2)
③⇾ swap (4, 6)
①⇒ Swap (3, 6)
①⇒ Swap (5, 6)
⇒ Done is still 0. So while loop executes again.
①⇾ no swap (6, 5)
done = 1
②⇾ No swap (5, 3)
③⇾Swap (3, 4)
So, array [3] = 3
①⇒ 1st for i = 0 <= 4 a[0] < a[1] ≃ 3<5 so perform swapping
done=
①⇒ no swap (3, 1)
②⇾ perform swap (1, 4)
①⇒ perform swap (1, 6)
①⇒ perform swap (1, 2)
①⇒ (done is still 0)
for i = 5 >= 1 a[5] > a[4] ≃ 1>2 – false. So, no swapping to be done
②⇾ no swap (6, 2)
③⇾ swap (4, 6)
①⇒ Swap (3, 6)
①⇒ Swap (5, 6)
⇒ Done is still 0. So while loop executes again.
①⇾ no swap (6, 5)
done = 1
②⇾ No swap (5, 3)
③⇾Swap (3, 4)
So, array [3] = 3
Question 15 
0  
1  
2  
3 
Question 15 Explanation:
n=++m; (pre)
n=11
n1=m++ (post)
Here, n1=11, but m will be updated to 12.
n & n1 decrements 11 to 10 & subtracting gives us zero.
Question 16 
1  
2  
4  
6 
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
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 
f(s,*s)  
i= f(i,s)  
f(i,*s)  
f(i,*p) 
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
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 
2016  
2017  
2018  
2019 
Question 18 Explanation:
For the first mystery (&a, &b);
temp = ptr b
ptr b = ptr a
ptr a = temp
If (a
Hence, a = 2016 will be printed.
Question 19 
a != n  
b != 0  
b > (a + 1)  
b != a 
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.
{
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 
3 1 2 2 1 3 4 4 4  
3 1 2 1 1 1 2 2 2  
3 1 2 2 1 3 4  
3 1 2 1 1 1 2 
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 
6, 2  
6, 6  
4, 2  
4, 4 
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 
30  
31  
32  
33 
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 
X^{Y} =a^{b}  
(res*a)^{Y} = (res*X)^{b}  
X^{Y} =res*a^{b}  
X^{Y} = (res*a)^{b} 
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.
x^{y}=res*a^{b}
2^{3}=2*2^{2}=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 (2^{3})
{
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.
x^{y}=res*a^{b}
2^{3}=2*2^{2}=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 (2^{3})
Question 24 
3  
4  
5  
6 
Question 24 Explanation:
Given
f(a, 5) ⇒ f(100, 5)
f(a, 5) ⇒ f(100, 5)
Question 25 
5  
6  
7  
8 
Question 25 Explanation:
Function f_{1} will not swap the value of 'a' and 'b' because f_{1} is call by value.
But f_{2} will swap the value of 'b' and 'c' because f_{2} 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
But f_{2} will swap the value of 'b' and 'c' because f_{2} 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 
2036, 2036, 2036  
2012, 4, 2204  
2036, 10, 10  
2012, 4, 6 
Question 26 Explanation:
⇒ Address of x = 2000
⇒ x [4] [3] can represents that x is a 2dimensional 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
⇒ x [4] [3] can represents that x is a 2dimensional 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 
{r = qx+y ∧ r  
{x = qy+r ∧ r  
{y = qx+r ∧ 0  
{q+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
⇒ x = qy + r
Question 28 
5  
6  
7  
8 
Question 28 Explanation:
Note: Out of syllabus.
Question 29 
n^{3}  
n(log n) ^{2}  
nlog n  
nlog (log n) 
Question 29 Explanation:
int fun1 (int n) {
int i, j, k, p, q = 0;
for (i=1; i
return q;
}
∴ nlog(logn)
int i, j, k, p, q = 0;
for (i=1; i
return q;
}
∴ nlog(logn)
Question 30 
ABCD EFGH
 
ABCD  
HGFE DCBA
 
DCBA 
Question 30 Explanation:
if condition fails
& returns controls
∴ DCBA will be pointed
Question 31 
51  
52  
53  
54 
Question 31 Explanation:
Recurrence Relation is
f(n) = 1; if n = 1
f(n) = 1; if n = 1
Question 32 
2  
2  
1  
15 
Question 32 Explanation:
When first time stkFunc (1,10) will be called then, inside Switch(opcode) the control will go to CaseI, where size=10.
When next time stkFunc (0,5) is called then, inside Switch(opcode), the control will go to Case0, 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 = 21 = 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 = 11 = 0 and value of A[0] will get returned, i.e., 5.
Finally the two values 10 & 5 will be added and printed.
When next time stkFunc (0,5) is called then, inside Switch(opcode), the control will go to Case0, 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 = 21 = 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 = 11 = 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 
12  
120400  
1204  
1034 
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.
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 35 
140  
150  
160  
170 
Question 35 Explanation:
**ptr = 40
∴ printf (“%d%d”, p + r – p, p + r) will print 140.
Question 36 
10  
11  
12  
13 
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
= 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 
230  
240  
250  
260 
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
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 
Compilation fails.  
Execution results in a runtime error.  
On execution, the value printed is 5 more than the address of variable i.  
On execution, the value printed is 5 more than the integer value entered. 
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.
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 
9  
10  
11  
12 
Question 39 Explanation:
func (435)
count = 0 Shift right of 1, which means the number gets half.
while (num)
{ Shift left of 1, which means, the number gets doubled.
count++;
num>>=1;
}
return (count); 435/2 = 217/2 = 108/2 = 54/2 = 27/2 = 13/2 = 6/2 = 3/2 = 1/2 = 0
Count: 1, 2, 3, 4, 5, 6, 7, 8, 9. Χ
(or)
(435)_{10} = (110110011)_{2}
The given program counts total number of bits in binary representation and fails when while (num) becomes all zeroes.
count = 0 Shift right of 1, which means the number gets half.
while (num)
{ Shift left of 1, which means, the number gets doubled.
count++;
num>>=1;
}
return (count); 435/2 = 217/2 = 108/2 = 54/2 = 27/2 = 13/2 = 6/2 = 3/2 = 1/2 = 0
Count: 1, 2, 3, 4, 5, 6, 7, 8, 9. Χ
(or)
(435)_{10} = (110110011)_{2}
The given program counts total number of bits in binary representation and fails when while (num) becomes all zeroes.
Question 40 
Suppose n and p are unsigned int variables in a C program. We wish to set p to ^{n}C_{3}. If n is large, which one of the following statements is most likely to set p correctly?
p = n * (n1) * (n2) / 6;  
p = n * (n1) / 2 * (n2) / 3;  
p = n * (n1) / 3 * (n2) / 2;  
p = n * (n1) * (n2) / 6.0; 
Question 40 Explanation:
n & p are unsigned int variable.
From the options n*(n1)*(n2) will go out of range. So eliminate A & D.
n*(n1) is always an even number. So subexpression n(n1)/2 also an even number.
n*(n1)/ 2*(n2), gives a number which is a multiple of 3. So dividing with 3 will not have any loss. Hence B is option.
From the options n*(n1)*(n2) will go out of range. So eliminate A & D.
n*(n1) is always an even number. So subexpression n(n1)/2 also an even number.
n*(n1)/ 2*(n2), gives a number which is a multiple of 3. So dividing with 3 will not have any loss. Hence B is option.
Question 41 
1.73  
1.74  
1.75  
1.76 
Question 41 Explanation:
double f(double x){
if( abs(x*x – 3) < 0.01) return x;
else return f(x/2 + 1.5/x);
}
We know that for
1) abs(x*x–3) < 0.01
x^{2} – 3 < 0.01 & – (x^{2} – 3) < 0.01
x^{2} < 3.01 & –x^{2} < 2.99
x < 1.73 & x < 1.72
2) x = x/2 + 1.5/x
x=(x^{2}+(1.5)2)/2x
x=(x^{2}+3)/2x⇒2x^{2}x^{2}=3
x^{2}=3
x=√3=1.732
Whichever the case we get around 1.72, 1.73 & max 1.74.
if( abs(x*x – 3) < 0.01) return x;
else return f(x/2 + 1.5/x);
}
We know that for
1) abs(x*x–3) < 0.01
x^{2} – 3 < 0.01 & – (x^{2} – 3) < 0.01
x^{2} < 3.01 & –x^{2} < 2.99
x < 1.73 & x < 1.72
2) x = x/2 + 1.5/x
x=(x^{2}+(1.5)2)/2x
x=(x^{2}+3)/2x⇒2x^{2}x^{2}=3
x^{2}=3
x=√3=1.732
Whichever the case we get around 1.72, 1.73 & max 1.74.
Question 42 
The function returns 0 for all values of j.  
The function prints the string something for all values of j.  
The function returns 0 when j = 50.  
The function will exhaust the runtime stack or run into an infinite loop when j = 50. 
Question 42 Explanation:
int f(int j) // if j=50,
{ i is also 50,
static int i = 50; if (i == j) // True
int k; prints something
if (i == j) and called f(50) again,
{ there is no base condition
printf(“something”); to get out of recursion.
k = f(i); So it goes into infinite loop
return 0; when j=50.
}
else return 0;
}
{ i is also 50,
static int i = 50; if (i == j) // True
int k; prints something
if (i == j) and called f(50) again,
{ there is no base condition
printf(“something”); to get out of recursion.
k = f(i); So it goes into infinite loop
return 0; when j=50.
}
else return 0;
}
Question 43 
The matrix A itself  
Transpose of the matrix A  
Adding 100 to the upper diagonal elements and subtracting 100 from lower diagonal elements of A  
None of the above 
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.
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) = X^{5 }+ 4X^{3 }+ 6X + 5 for a given value of X, using only one temporary variable is ________.
7  
8  
9  
10 
Question 44 Explanation:
The minimum number of arithmetic operations required to evaluate
P(X)=x^{5}+4x^{3}+6x+5
=x(x^{4}+4x^{2}+6)+5
=x(x(x^{3}+4x)+6)+5
=x(x(x(x^{2}+4))+6)+5
=x(x(x(x(x)+4))+6)+5
4 multiplications & 3 additions.
4 + 3 = 7
P(X)=x^{5}+4x^{3}+6x+5
=x(x^{4}+4x^{2}+6)+5
=x(x(x^{3}+4x)+6)+5
=x(x(x(x^{2}+4))+6)+5
=x(x(x(x(x)+4))+6)+5
4 multiplications & 3 additions.
4 + 3 = 7
Question 45 
Θ(n^{2})  
Θ(n^{2} log n)  
Θ(n^{3})  
Θ(n^{3} logn) 
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(n^{2}logn)
= (n/2+1).n/2 ∙log n
= (n^{2}log n)
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(n^{2}logn)
= (n/2+1).n/2 ∙log n
= (n^{2}log n)
Question 46 
L_{2} is contextfree.  
L_{1}∩ L_{2} is contextfree.  
Complement of L_{2} is recursive.  
Complement of L_{1} is contextfree but not regular. 
Question 46 Explanation:
L_{1} = 0*1*0* which is regular language and in L_{2} 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 L_{1}∩ L_{2} is contextfree.
L_{2} is CFL and CFL is not closed under complementation so we have to assume L_{2} as CSL (since every CFL is CSL) and CSL is closed under complement so Complement of L_{2} must be CSL and every CSL is recursive so Complement of L_{2} is recursive.
Since L_{1} is regular and regular language is closed under complement so complement of L_{1} must be regular and hence the statement Complement of L_{1} is contextfree but not regular is a false statement.
Intersection of a regular language with a context free language is context free language (by closure properties of regular language) So L_{1}∩ L_{2} is contextfree.
L_{2} is CFL and CFL is not closed under complementation so we have to assume L_{2} as CSL (since every CFL is CSL) and CSL is closed under complement so Complement of L_{2} must be CSL and every CSL is recursive so Complement of L_{2} is recursive.
Since L_{1} is regular and regular language is closed under complement so complement of L_{1} must be regular and hence the statement Complement of L_{1} is contextfree but not regular is a false statement.
Question 47 
None  
2 only  
3 and 4 only  
4 only 
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.
1, 2 works fine, 3, 4 carries flaw.
Question 48 
No Choice  
Choice A  
Program gives no output as it is erroneous 
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.
So,
→ Choice A
→ Choice B. No choice. Is the output.
Question 50 
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.
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 
GATE2011  
E2011  
2011  
011 
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.
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 
9  
8  
5  
2 
Question 52 Explanation:
∴ 1+0+0+0+0+0+0+0+0+1+0 = 2
Question 54 
2 2  
2 1  
0 1  
0 2 
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 
9  
5  
15  
19 
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, n1);
else
return *a – f(a+1, n1);
⇒12+(7(13(4+(11(6)))))
⇒12+(7(13(4+5)))
⇒12+7(4)
⇒12+3
⇒15
if (n <= 0)
return 0;
else if (*a % 2 = = 0)
return *a + f(a+1, n1);
else
return *a – f(a+1, n1);
⇒12+(7(13(4+(11(6)))))
⇒12+(7(13(4+5)))
⇒12+7(4)
⇒12+3
⇒15
Question 56 
6  
8  
14  
15 
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(n1,&x)+fun(n2,&x), where fun(n1,&x) is storing in variable ‘t’ & fun(n2,&x) is storing in variable x(*fp).
∴ The program is nth Fibonacci number.
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(n1,&x)+fun(n2,&x), where fun(n1,&x) is storing in variable ‘t’ & fun(n2,&x) is storing in variable x(*fp).
∴ The program is nth Fibonacci number.
Question 57 
x = 3, y = 4, z = 2  
x = 6, y = 5, z = 3
 
x = 6, y = 3, z = 5
 
x = 5, y = 4, z = 5 
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.
→ 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 
18  
19  
21  
22 
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
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 
?1 is (getchar( ) != ’\n’) ?2 is getchar(c);  
?1 is (c = getchar( ) ) != ’\n’) ?2 is getchar(c);  
?1 is (c != ’\n’) ?2 is putchar(c);  
?1 is ((c = getchar()) != ’\n’) ?2 is putchar(c); 
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);
{
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 
1661 and 1640  
59 and 59  
1640 and 1640
 
1640 and 1661

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
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 
Ic, IId, IIIb, IVa  
Ia, IId, IIIc, IVb  
Id, IIc, IIIb, IVa  
Ic, IId, IIIa, IVb

Question 61 Explanation:
Note: Out of syllabus.
Question 62 
dlrow  
Null String  
dlrld  
worow

Question 62 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 63 
5, 5  
5, 4  
4, 5  
4, 4 
Question 63 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.
{Swap3 (&num1, &num2) ; }"
Statement is true, so call by reference will be performed and the value of num1 and num2 will get exchanged.
Question 64 
2, 3  
2, 4  
3, 2  
3, 3 
Question 64 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 decrement 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.
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 decrement 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 65 
Question 65 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
*(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 66 
010110101  
010101101  
10110101  
10101101 
Question 66 Explanation:
So, after traversing the tree we get:
10101101
Question 67 
Both P1 and P2  
P2 only  
P1 only  
Neither P1 nor P2 
Question 67 Explanation:
P1 prints same as the original program.
But P2 prints the reverse of original sequence printed by original program.
But P2 prints the reverse of original sequence printed by original program.
Question 68 
5  
7  
9  
18 
Question 68 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
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 69 
(i) and (iii)  
(i) and (iv)  
(ii) and (iii)  
(ii) and (iv) 
Question 69 Explanation:
The function can be terminated for all the values which can have factor of 2{(2x)2 == 0}, so (i) is false and (ii) is true.
→ Let n=3, then it is terminated in 2^{nd} 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.
→ Let n=3, then it is terminated in 2^{nd} 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 70 
9  
8  
7  
6 
Question 70 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 71 
Call by value : i = 70, j = 10; Call by reference : i = 60, j = 70  
Call by value : i = 50, j = 60; Call by reference : i = 50, j = 70  
Call by value : i = 10, j = 70; Call by reference : i = 100, j = 60  
Call by value : i = 100, j = 60; Call by reference : i = 10, j = 70 
Question 71 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 varible '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.
'i' is a global variable. Then in main( ) a local variable 'j' as integer declared, i.e., j=60 and global varible '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 72 
x = 10, y = 10  
x = 20, y = 10  
x = 10, y = 20  
x = 20, y = 20

Question 72 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 whicg called it, i.e., procedure f( ) which has a local i=20, which will be taken and 20 will be printed.
Question 73 
Early, late, decrease, increase  
Late, early, increase, decrease  
Late, early, decrease, increase  
Early, late, increase, decrease 
Question 73 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.
Dynamic scoping requires late binding (during execution time).
Late binding decreases efficiency as this binding needs to be done at run time.
Question 74 
S1  
S2 and S3  
S2 and S4
 
S2 and S5

Question 74 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.
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 75 
S1 and S2
 
S1 and S4
 
S3  
S1 and S5

Question 75 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.
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 76 
jungle, n, 8, ncestor  
etter, u, 6, ungle  
cetter, k, 6, jungle  
etter, u, 8, ncestor 
Question 76 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".
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 77 
a = 0, b = 3 a = 0, b = 3  
a = 3, b = 0 a = 12, b = 9  
a = 3, b = 6 a = 3, b = 6  
a = 6, b = 3 a = 15, b = 12 
Question 77 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
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 78 
8, 12, 7, 23, 8  
8, 8, 7, 23, 7  
12, 12, 27, 31, 23  
12, 12, 27, 31, 56 
Question 78 Explanation:
1) a[0][2] = *(*(a+0)+2)
It returns the value of 3^{rd} element in a1.
First printf print 8.
2) *a[2] = *(*(a+2))
It returns the value of 1^{st} element in a3.
Second printf print 12.
3) *++a[0] = *(++(*(a+0)))
a[0] is pointing to 1^{st} element in a1.
++a[0]  after preincrement performed, now a[0] is pointing to 2^{nd} element in a1.
*++a[0] return the value of 2^{nd} 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 1^{st} element in a2.
*(++a)[0] returns the value of 1^{st} element in a2.
Fourth printf print 23.
5) a[1][+1] = *(*(a1)+1)
(a1) is pointing to a1.
*(a1) is pointing to the 2^{nd} element in a1, because in 3^{rd} printf already a1 was incremented by 1.
*(a1)+1 is pointing 3^{rd} element in a1.
*(*(a1)+1) returns the value of 3^{rd} element in a1, i.e., 8.
It returns the value of 3^{rd} element in a1.
First printf print 8.
2) *a[2] = *(*(a+2))
It returns the value of 1^{st} element in a3.
Second printf print 12.
3) *++a[0] = *(++(*(a+0)))
a[0] is pointing to 1^{st} element in a1.
++a[0]  after preincrement performed, now a[0] is pointing to 2^{nd} element in a1.
*++a[0] return the value of 2^{nd} 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 1^{st} element in a2.
*(++a)[0] returns the value of 1^{st} element in a2.
Fourth printf print 23.
5) a[1][+1] = *(*(a1)+1)
(a1) is pointing to a1.
*(a1) is pointing to the 2^{nd} element in a1, because in 3^{rd} printf already a1 was incremented by 1.
*(a1)+1 is pointing 3^{rd} element in a1.
*(*(a1)+1) returns the value of 3^{rd} element in a1, i.e., 8.
Question 79 
(n == 0)  (m == 1)  
(n == 0) && (m == 1)  
(n == 0)  (m == n)  
(n == 0) && (m == n) 
Question 79 Explanation:
We know that,
^{m}C_{0} = 1
^{n}C_{n} = 1
^{m}C_{0} = 1
^{n}C_{n} = 1
Question 80 
(i)  B, (ii)  D, (iii)  E, (iv)  F, (v)  G, (vi)  A  
(i)  C, (ii)  A, (iii)  E, (iv)  D, (v)  H, (vi)  F  
(i)  C, (ii)  F, (iii)  H, (iv)  A, (v)  G, (vi)  D  
(i)  B, (ii)  E, (iii)  C, (iv)  F, (v)  G, (vi)  H 
Question 80 Explanation:
Note: Out of syllabus.
Question 81 
A function that takes an integer pointer as argument and returns an integer.  
A function that takes an integer as argument and returns an integer pointer.  
A pointer to a function that takes an integer pointer as argument and returns an integer.  
A function that takes an integer pointer as argument and returns a function pointer. 
Question 81 Explanation:
int ( * f) (int * )
→ A pointer to a function which takes integer as a pointer and return an integer value.
→ A pointer to a function which takes integer as a pointer and return an integer value.
Question 82 
A common property of logic programming languages and functional languages is:
both are procedural languages
 
both are based on λcalculus
 
both are declarative
 
both use Hornclauses

Question 82 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 83 
(i) and (ii) only
 
(i) and (iv) only
 
(i), (ii) and (iv) only
 
(i), (iii) and (iv) only

Question 83 Explanation:
Abstraction, encapsulation and inheritance are three main features of OOP language.
Question 84 
no compile warning or error  
some compilerwarnings not leading to unintended results  
some compilerwarnings due to typemismatch eventually leading to unintended results
 
compiler errors 
Question 84 Explanation:
When a function is called before its declaration then it leads to compiler error.
Question 85 
8, 4, 0, 2, 14
 
8, 4, 0, 2, 0
 
2, 0, 4, 8, 14
 
2, 0, 4, 8, 0

Question 85 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.
⇒ 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 86 
A : count [a[j]]++ and B : count[b[j]]–  
A : count [a[j]]++ and B : count[b[j]]++  
A : count [a[j++]]++ and B : count[b[j]]–  
A : count [a[j]]++and B : count[b[j++]]– 
Question 86 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 nonzero elements is found, it returns 0 indicating that strings are not anagram to each other.
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 nonzero elements is found, it returns 0 indicating that strings are not anagram to each other.
Question 87 
1, 2, 3, 4, 5, 6, 7  
2, 1, 4, 3, 6, 5, 7  
1, 3, 2, 5, 4, 7, 6  
2, 3, 4, 5, 6, 7, 1 
Question 87 Explanation:
It is nothing but a pairwise swapping of the linked list.
Question 88 
a[j] – a[i] > S  
a[j] – a[i] < S  
a[i] – a[j] < S  
a[i] – a[j] > S

Question 88 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'.
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 89 
only I and II  
only I and IV  
only II and III  
only III and IV 
Question 89 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.
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 90 
5  
8  
9  
20 
Question 90 Explanation:
Hence, 9 is the answer.
Question 91 
call swap (x, y)
 
call swap (&x, &y)
 
swap (x,y) cannot be used as it does not return any value
 
swap (x,y) cannot be used as the parameters are passed by value

Question 91 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(*).
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 92 
The goal of structured programming is to
have well indented programs
 
be able to infer the flow of control from the compiled code
 
be able to infer the flow of control from the program text
 
avoid the use of GOTO statements

Question 92 Explanation:
Structured programming: Which is aimed at improving the clarity, quality and development time of a computer programming by making extensive use of the structured control flow constructs of selection and repetition of block structures and subroutines in contrast to using simple tests and jumps such as goto statements.
Question 93 
5  
6  
7  
8 
Question 93 Explanation:
The value return by f(1) = 7
Question 94 
n = d_{1}d_{2}…d_{mi} and rev = d_{m}d_{m1}…d_{mi+1}
 
n = d_{mi+1}…d_{m1}d_{m} or rev = d_{mi}…d_{2}d_{1}
 
n ≠ rev  
n = d_{1}d_{2}…d_{m} and rev = d_{m}…d_{2}d_{1}

Question 94 Explanation:
In each iteration the right most digit of n is going to make to the right end of the reverse.
Question 95 
gnirts  
string
 
gnirt  
no output is printed

Question 95 Explanation:
Every string is to be end with '\0'.
P[0] = S[71] = 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.
P[0] = S[71] = 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 96 
(i), (iv), (vi), (viii)
 
(i), (iv), (vii)  
(i), (iii), (v), (vi), (viii)
 
(ii), (v), (viii)

Question 96 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 97 
x + y using repeated subtraction
 
x mod y using repeated subtraction
 
the greatest common divisor of x and y
 
the least common multiple of x and y

Question 97 Explanation:
Given code is same as Euclid's Algorithm for finding Greatest Common Divisor(GCD).
Question 98 
P  2, Q  3, R  4, S  1
 
P  4, Q  3, R  2, S  1
 
P  3, Q  4, R  1, S  2
 
P  3, Q  4, R  2, S  1

Question 98 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.
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 99 
x = 1 + x;  
x = 1  x;  
x = x  1;  
x = 1 % x; 
Question 99 Explanation:
x = 1  x
For x = 0, it gives 1.
For x = 1, it gives 0.
For x = 0, it gives 1.
For x = 1, it gives 0.
Question 100 
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?
abcd  
dcba  
abad  
cabd 
Question 100 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.
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 101 
Question 101 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 viceversa.
In (D) , given statements is wrong as temporary variable needs to be assigned some value and not viceversa.
Question 102 
43 80  
42 74  
33 37  
32 32 
Question 102 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.
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 103 
?1 is getchar() ! = ‘\n’ ?2 is getchar(c);  
?1 is (c = getchar()); ! = ‘\n’ ?2 is getchar(c);  
?1 is c! = ‘\n’ ?2 is putchar(c);  
?1 is (c = getchar()) ! = ‘\n’ ?2 is putchar(c); 
Question 103 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, putchat( ) gets executed and prints the last character and then the function returns to its previous call and prints last 2^{nd} character and so on.
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, putchat( ) gets executed and prints the last character and then the function returns to its previous call and prints last 2^{nd} character and so on.
Question 104 
AB UV VW VW  
AB UV AB VW  
AB UV UV VW  
AB UV VW UV 
Question 104 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).
→ 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 105 
(∀x) [(∃y) [B(x,y) ∧ C(y)] ⇒ A(x)] ∧ ¬(∃x)[B(x,x)]  
(∀x) [(∀y) [B(x,y) ∧ C(y)] ⇒ A(x)] ∧ ¬(∃x)[B(x,x)]  
(∀x) [(∃y) [B(x,y) ∧ C(y)] ⇒ A(x)] ∨ ¬(∃x)[B(x,x)]  
(∀x) [(∀y) [B(x,y) ∧ C(y)] ⇒ A(x)] ∧ (∃x)[B(x,x)] 
Question 105 Explanation:
Note: This is not in gate syllabus. Please ignore this question.
Question 106 
115, 220  
25, 220
 
25, 15  
115, 105

Question 106 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
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 107 
115, 220  
25, 220
 
25, 15
 
115, 105

Question 107 Explanation:
In dynamic,
In void P(x)
{ int i = 10;
print(x + 10); ⇒ 105+10=115 prints
print (x); ⇒ print x=220;
In void P(x)
{ int i = 10;
print(x + 10); ⇒ 105+10=115 prints
print (x); ⇒ print x=220;
Question 108 
1 2 1  
2 1 1  
2 1 2
 
2 2 2 
Question 108 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
Note: The given question is not in the present syllabus
Question 109 
{mm ≤ n, (∃i)[m=i!]}
 
{mm ≤ n, (∃i)[m=i^{2}]}
 
{mm ≤ n, m is prime}
 
{ } 
Question 109 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.
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 110 
12 7 6
 
22 12 11
 
14 6 6
 
7 6 6 
Question 110 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=71=6
x=7(Print x→II)
comes to main ( ),
print x=*y=6 (print x→III)
Output: 12 7 6
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=71=6
x=7(Print x→II)
comes to main ( ),
print x=*y=6 (print x→III)
Output: 12 7 6
Question 111 
In the C language
At most one activation record exists between the current activation record and the activation record for the main  
The number of activation records between the current activation record and the activation record for the main depends on the actual function calling sequence.  
The visibility of global variables depends on the actual function calling sequence.  
Recursion requires the activation record for the recursive function to be saved on a different stack before the recursive fraction can be called. 
Question 111 Explanation:
In C Language a function can create activation record from the created function stack.
Question 112 
An array, each element of which is a pointer to a structure of type node  
A structure of 2 fields, each field being a pointer to an array of 10 elements  
A structure of 3 fields: an integer, a float, and an array of 10 elements  
An array, each element of which is a structure of type node 
Question 112 Explanation:
The given code represents an array of s[ ], in this each element is a pointer to structure of type node.
Question 113 
X – 1 Y – 3 Z – 2  
X – 2 Y – 1 Z – 3  
X – 3 Y – 2 Z – 1  
X – 3 Y – 1 Z – 2 
Question 113 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.
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 114 
Aliasing in the context of programming languages refers to
multiple variables having the same memory location  
multiple variables having the same value  
multiple variables having the same identifier  
multiple uses of the same variable 
Question 114 Explanation:
In computer programming, aliasing refers to the situation where the same memory location can be accessed using different names.
Question 115 
22 bytes  
14 bytes  
18 bytes  
10 bytes 
Question 115 Explanation:
short [5] = 5×2 = 10
max[float, long] = max [4, 8] = 8
Total = short[5] + max[float,long] = 10 + 8 = 18
max[float, long] = max [4, 8] = 8
Total = short[5] + max[float,long] = 10 + 8 = 18
Question 116 
10  
4  
6  
7 
Question 116 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.
i=1; count=1
i=2; count=3
i=3; count=6
i=4; count=10
It return count value is 10.
Question 117 
Theory Explanation is given below. 
Question 117 Explanation:
Note: Out of syllabus.
Question 118 
Given the programming constructs (i) assignment (ii) for loops where the loop parameter cannot be changed within the loop (iii) ifthenelse (iv) forward go to (v) arbitrary go to (vi) nonrecursive 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.
(ii), (iii), (iv)  
(v), (vii), (viii)  
(vi), (vii), (viii)  
(iii), (vii), (viii) 
Question 118 Explanation:
Arbitrary goto, recursive call and repeat may enter infinite loop and hence terminates program may not be able to answer if the program does terminate.
Question 119 
Finds the maximum of a, b, and c  
Finds the minimum of a, b and c  
Finds the middle number of a, b, c  
None of the above

Question 119 Explanation:
Try for (3,2,2), it will go for infinite loop.
Question 120 
89  
90  
91  
92 
Question 120 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
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 121 
5  
25  
36  
42 
Question 121 Explanation:
If it is call by reference then answer is 42.
If it is call by value then answer is 36.
If it is call by value then answer is 36.
Question 122 
x or A, y, x of B and z in S1 and x of B, y and i in S2
 
x or B, y and z in S1 and x of B, i and z in S2  
x or B, z and y in S1 and x of A, i and y in S2
 
None of the above 
Question 122 Explanation:
Note: Out of syllabus.
Question 123 
10  
20  
10  
None 
Question 123 Explanation:
X is remains unchanged. As the if condition is becomes false.
X = 10
X = 10
Question 124 
I  
II  
III  
All of the above 
Question 124 Explanation:
Note: Out of syllabus.
Question 125 
Computes the LCM of two numbers  
Divides the larger number by the smaller number  
Computes the GCD of two numbers  
None of the above 
Question 125 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.
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 126 
2  
Run time error  
None of the above 
Question 126 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.
X in the procedure FIND is a local variable. No change will be reflected in global variable X.
Question 127 
2800  
2400  
2000  
1200 
Question 127 Explanation:
Note: Out of syllabus.
Question 128 
1, because m is a local variable in P  
0, because m is the actual parameter that corresponds to the formal parameter in p
 
0, because both x and y are just reference to m, and y has the value 0  
1, because both x and y are just references to m which gets modified in procedure P  
none of the above 
Question 128 Explanation:
0, because global m is not modified, m is just passed to formal argument of P.
Question 129 
0, because n is the actual parameter corresponding to x in procedure Q.  
0, because n is the actual parameter to y in procedure Q.  
1, because n is the actual parameter corresponding to x in procedure Q.  
1, because n is the actual parameter corresponding to y in procedure Q.  
none of the above 
Question 129 Explanation:
0, because n is just passed to formal parameters of Q and no modification in global n.
Question 130 
PARAM, P, Q  
PARAM, P  
PARAM, Q  
P, Q  
none of the above 
Question 130 Explanation:
Since m is defined global it is visible inside all the procedures.
Question 131 
exchanges a and b  
doubles a and stores in b  
doubles b and stores in a  
leaves a and b unchanged  
none of the above 
Question 131 Explanation:
Exchanges a and b.
Let us consider a=5; b=2
a := a+b = 5+2 = 7
b := ab = 72 = 5
a := ab = 75 = 2
O/P: a=2; b=5
Let us consider a=5; b=2
a := a+b = 5+2 = 7
b := ab = 72 = 5
a := ab = 75 = 2
O/P: a=2; b=5
Question 133 
41 
Question 133 Explanation:
The recurrence relation for the no. of calls is
T(n) = T(n1) + T(n2) + 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
T(n) = T(n1) + T(n2) + 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 134 
None of the above 
Question 134 Explanation:
Note: Out of syllabus.
Question 135 
10  
11  
3  
None of the above 
Question 135 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
W(n)=W(3)
Procedure W(var x; int)
begin
x = x+1 = 3+1 = 4
Print x → Print x=4
end
Question 136 
10, 3  
31, 3  
27, 7  
None of the above 
Question 136 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).
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 138 
(a)  (s), (b)  (r), (c)  (p), (d)  (q) 
Question 138 Explanation:
Note: Out of syllabus.
Question 139 
In which of the following case(s) is it possible to obtain different results for callbyreference and callbyname parameter passing?
Passing an expression as a parameter  
Passing an array as a parameter  
Passing a pointer as a parameter  
Passing as array element as a parameter  
Both A and D 
Question 139 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:
Callbyreference: 6
Callbyname: 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 precedenc e)
= 1+2+2
= 5
Output differs.
Answer: A, 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:
Callbyreference: 6
Callbyname: 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 precedenc e)
= 1+2+2
= 5
Output differs.
Answer: A, D
Question 140 
An unrestricted use of the "go to" statement is harmful because of which of the following reason (s):
It makes it more difficult to verify programs.  
It makes programs more inefficient.  
It makes it more difficult to modify existing programs.  
It results in the compiler generating longer machine code. 
Question 140 Explanation:
Dijkstra's argued that unrestricted goto statements should abolished from the higherlevel languages because they complicated the task of analyzing and verifying the correctness of programs.
Question 141 
3, 6  
6, 7  
3, 7  
None of the above. 
Question 141 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)/(n3), i.e., (4+2)/(43)=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 142 
3, 6  
6, 7  
3, 7  
None of the above 
Question 142 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.
There are 142 questions to complete.