Programming Language
Programming Language
India’s Best Online Coaching Platform for GATE, ESE, PSUs, SSC-JE, RRB-JE, SSC, Banks, Groups & PSC Exams
Enjoy a smooth online learning experience in various languages at your convenience
99 Programming Languages
case 3: printf (“\n%d”, i+k); For large values of y, the return value of the function
default: printf (“\n%d”, i+k); f best approximates
} (a) xy
}
(b) ex
return 0; (c) ln(1+x)
}
(d) xx
The number of times printf statement is executed
is ______.
07. Consider the following C-program:
double foo(double); /* Line 1 */
Functions
int main ( )
{
05. Consider the following C function definition
double da, db;
int Trial (int a, int b, int c)
{ // input da
08. Consider the function func shown below: 10. The following function computes the maximum
value contained in an integer
int func(int num)
array p[ ]of size n (n >= 1).
{
int max(int *p, int n) {
int count = 0;
int a = 0, b = n – 1;
while (num)
while (__________)
{
{
count ++;
if (p[a] <= p[b]) { a = a+1; }
num >>= 1;
else { b = b-1; }
}
}
return (count); return p[a];
} }
The value returned by func(435) is ____. The missing loop condition is
(a) a != n (b) b != 0
09. Consider the following C program. (c) b > (a + 1) (d) b != a
void f(int, short);
11. The following function computes XY for positive
void main( ) integers X and Y.
{ int exp(int X, int Y)
{
int i = 100;
int res = 1, a = X, b = Y;
short s = 12; while (b != 0 )
short *p = &s; {
if ( b%2 == 0)
__________ ; // call to f( )
{
} a = a*a; b = b/2;
}
else
Which one of the following expressions, when
{
placed in the blank above, will NOT result in a type
res = res*a; b = b-1;
checking error?
}
(a) f(s,*s) }
(b) i = f(i,s) return res;
}
(c) f(i,*s)
Which one of the following condition is TRUE
(d) f(i,*p) 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
India’s Best Online Coaching Platform for GATE, ESE, PSUs, SSC-JE, RRB-JE, SSC, Banks, Groups & PSC Exams
Enjoy a smooth online learning experience in various languages at your convenience
101 Programming Languages
12. int Get(int a, int b) the current activation record and the activation
17. Choose the correct option to fill ?1 and ?2 so that 18. What is the return value of the function foo when it
the program below prints an input string in reverse is called as foo (345, 10)?
order. Assume that the input string is terminated by (a) 345 (b) 12 (c) 5 (d) 3
a newline character.
void reverse (void) 19. What is the return value of the function foo when it
{ is called as foo (513, 2)?
int c; (a) 9 (b) 8 (c) 5 (d) 2
if (?1)
reverse ( ) ; 20. Consider the following C function.
?2
int fun(int n)
}
{
main ( )
int x = 1, k;
{
printf(“Enter Text”) ; if (n = = 1) return x;
printf(“\ n” ); for (k =1; k<n; ++k)
reverse ( ); x = x + fun(k) * fun(n–k);
printf (“\ n”); return x;
}
}
(a) ?1 is (getchar ( ) ! = ‘\ n’) The return value of fun(5) is _____.
?2 is getchar (c);
(b) ?1 is ((c = getchar ( ) )! = ‘\ n’)
Storage Classes
?2 is getchar (c);
(c) ?1 is (c ! = ‘\ n’)
21. The value of j at the end of the execution of the
?2 is putchar (c); following C program
(d) ?1 is ((c = getchar ( ) )! = ‘\ n’) int incr (int i)
?2 is putchar (c); {
static int count = 0;
Common Data for Questions 18 & 19 count = count + i;
return (count);
Consider the following recursive C function that }
takes two arguments: main ( )
Unsigned int foo (unsigned int n, unsigned int r) {
{ int i, j;
if (n > 0 ) for (i = 0; i <=4; i++)
return((n%r) + foo(n/r,r)); j = incr(i);
else return 0; }
} is:
(a) 10 (b) 4 (c) 6 (d) 7
India’s Best Online Coaching Platform for GATE, ESE, PSUs, SSC-JE, RRB-JE, SSC, Banks, Groups & PSC Exams
Enjoy a smooth online learning experience in various languages at your convenience
103 Programming Languages
Common Data for Questions 24 & 25 26. Consider the C function given below.
Consider the following C code segment. int f ( int j)
int a, b, c = 0 ; { static int i = 50 ;
void prtFun (void) ; int k ;
main ( ) if ( i = = j )
{ {
static int a = 1; // Line1 printf ( “ something”) ;
prtFun( ); k = f(i) ;
a+=1; return 0 ;
prtFun( ); }
printf (“ \n %d %d” , a, b) ; else return 0 ;
} }
Regular Live Doubt clearing Sessions | Free Online Test Series | ASK an expert
Affordable Fee | Available 1M | 3M | 6M |12M|18M and 24 Months Subscription Packages
104 Programming Languages
31. Consider the following three C functions: (a) What will be the output of the program?
[P1] int * g(void) (b) If abc(s) is called with a null-terminated string
{ s of length n characters (not counting the null
int x =10; (‘\0’) character), how many characters will be
return (&x); printed by abc(s)?
}
33. Consider the C program shown below.
[P2] int * g(void) #include <stdio.h>
{ #define print(x) printf (“%d”, x)
int * px; int x;
* px = 10; void Q(int z)
return px; {
} z += x; print(z);
}
[P3] int * g(void) void P(int *y)
{ {
int * px; int x = *y+2;
px=(int*)malloc(sizeof (int)); Q(x); *y = x–1;
*px=10; print(x);
return px; }
} main(void)
Which of the above three functions are likely to {
cause problems with pointers? x = 5;
(a) Only P3 (b) Only P1 and P3 P(&x);
(c) Only P1 and P2 (d) P1, P2 and P3 print(x);
}
32. Consider the following C program: The output of this program is
void abc(char *s) (a) 12 7 6
{ (b) 22 12 11
if(s[0]== ‘\0’) return; (c) 14 6 6
abc(s+1); (d) 7 6 6
abc(s+1);
printf(“%c”,s[0]); 34. Assume the following C variable declaration
} int * A[10], B[10] [10];
main( ) Of the following expressions
{ I. A[2]
abc(“123”); II. A[2] [3]
} III. B[1]
IV. B[2] [3]
Regular Live Doubt clearing Sessions | Free Online Test Series | ASK an expert
Affordable Fee | Available 1M | 3M | 6M |12M|18M and 24 Months Subscription Packages
106 Programming Languages
Which will not give compile-time errors if used 37. What is printed by the following C program?
as left hand sides of assignment statements in a C int f (int x, int *py, int * *ppz)
program? {
int y, z;
(a) I, II, and IV only * *ppz +=1; z =**ppz;
(b) II, III, and IV only *py +=2; y =*py;
x +=3;
(c) II and IV only
return x +y+ z;
(d) IV only }
void main ( )
35. Consider the following C program segment: {
int c, *b, * *a;
char p [20];
c =4; b =&c; a =&b;
char * s = “string”; printf( “%d”, f (c,b,a) ) ;
}
int length = strlen (s);
(a) 18 (b) 19 (c) 21 (d) 22
for (i = 0 ; i < length; i++)
38. What does the following program print?
p[i] = s[length – i];
#include <stdio.h>
printf(“%s”,p); void f (int *p, int *q)
The output of the program is {
(a) gnirts p = q;
*p = 2;
(b) string
}
(c) gnirt
int i = 0, j =1;
(d) no output is printed
int main ( )
{
36. What does the following C-statement declare? f(&i, & j);
int ( * f) (int * ) ; printf (“%d %d \ n”, i, j) ;
(a) A function that takes an integer pointer as return 0;
argument and returns an integer }
(b) A function that takes an integer as argument (a) 2 2 (b) 2 1 (c) 0 1 (d) 0 2
(a) GATE2011 (b) E2011 42. What is the output of the following C code? Assume
(c) 2011 (d) 011 that the address of x is 2000 (in decimal) and an
integer requires four bytes of memory?
40. Consider the following program in C language int main( )
# include <stdio.h>
{
main( )
unsigned int x[4] [3] = {(1,2,3), {4,5,6}, {7,8,9},
{
{10, 11, 12}};
int i ;
printf(“%u,%u,%u”, x+3,*(x+3), *(x+2)+3);
int *pi = &i;
}
scanf(“%d”, pi);
(a) 2036, 2036, 2036
printf(“%d\n”, i + 5);
(b) 2012, 4, 2204
}
Which one of the following statements is TRUE? (c) 2036, 10, 10
(a) Compilation fails (d) 2012, 4, 6
(b) Execution results in a runtime error.
(c) On execution, the value printed is 5 more than 43. Consider the following function written in the C
the address of variable i. programming language.
(d) On execution, the value printed is 5 more than void foo(char *a)
the integer value entered.
{
44. Consider the C program below. 46. Consider the following C program.
#include <stdio.h> #include<stdio.h>
int *A, stkTop; int main( )
int stkFunc(int opcode, int val) {
static int a[ ] = {10, 20, 30, 40, 50};
{
static int size = 0, stkTop = 0; static int *p[ ] = {a, a+3, a+4, a+1, a+2};
India’s Best Online Coaching Platform for GATE, ESE, PSUs, SSC-JE, RRB-JE, SSC, Banks, Groups & PSC Exams
Enjoy a smooth online learning experience in various languages at your convenience
111 Programming Languages
56. #include<stdio.h>
Parameter Passing Techniques
main( )
{
char s[ ]={‘a’, ‘b’, ‘c’, ‘\n’, ‘c’, ‘\0’}; 58. Consider the program below in a hypothetical
char *p, *str,*str1; language which allows global variables and a
p = &s[3]; choice of call by reference or call by value methods
str=p; of parameter passing.
str1=s; int i;
printf(“%c”, ++*p + ++*str1–32); Program main( )
{
}
int j = 60;
i = 50;
(a) M (b) A call f(i,j);
(c) B (d) C print i,j;
}
57. consider the program below: Procedure f(x,y)
#include <stdio.h> {
i = 100;
int fun(int n, int *fp)
x = 10;
{
y = y + i;
int t, f; }
if (n < = 1) Which one of the following options represents the
{ correct output of the program for the two parameter
*fp = 1; passing mechanisms?
return 1; (a) Call by value: i=70, j = 10;
} Call by reference: i=60, j=70
t = fun (n–1, fp); (b) Call by value: i=50, j = 60;
f = t + *fp; Call by reference: i=50, j =70
*fp = t; (c) Call by value: i=10, j = 70;
return f; Call by reference: i=100, j =60
} (d) Call by value: i=100, j = 60;
int main( ) Call by reference: i =10, j=70
{
int x = 15; 59. Consider the following C function
printf (“%d\n”, fun(5, &x)); void swap (int a, int b)
return 0; {
} int temp;
The value printed is: temp = a ;
a = b ;
(a) 6 (b) 8 b = temp ;
(c) 14 (d) 15 }
Regular Live Doubt clearing Sessions | Free Online Test Series | ASK an expert
Affordable Fee | Available 1M | 3M | 6M |12M|18M and 24 Months Subscription Packages
112 Programming Languages
In order to exchange the values of two variables x Determine its output, if the parameters are passed to
and y the procedure P by
(a) call swap(x, y) i. value
(b) call swap(&x, &y)
ii. reference
(c) swap(x, y) cannot be used as it does not return
any value
62. Consider the following program in pseudo pascal
(d) swap(x, y) cannot be used as the parameters
syntax.
are passed by value
program what:
60. What is the return value of f (p, p), if the value of p var z: integer;
is initialized to 5 before the call? procedure recur (x):
Note that the first parameter is passed by reference, begin if x ≤ 40 then
whereas the second parameter is passed by value.
begin x: =x + z;
int f (int &x, int c)
{ recur (x);
c = c – 1; z:=x+10;
if (c = = 0) return 1; end
x = x + 1; end(*recur*);
return f(x, c) * x;
begin (*what*)
}
(a) 3024 (b) 6561 z : =10;
(c) 55440 (d) 161051 recur(z);
writeln(z);
61. Consider the following pseudo-code (all data items end
are of type integer):
(a) Suppose the parameter to the procedure ‘recur’
procedure P (a, b, c); is passed by value.
a:=2; (i) What value is printed by the program?
c:=a+b; (ii) How many times is ‘recur’ called?
end {P};
begin (b) What value is printed by the program if the
x:=1; parameter is passed by reference?
y:=5;
z:=100; 63. What will be the output of the following program
P(x,x*y,z); assuming that parameter passing is
write (‘x=’,x, ‘z=’,z) (i) call by value
(ii) call by reference
end:
India’s Best Online Coaching Platform for GATE, ESE, PSUs, SSC-JE, RRB-JE, SSC, Banks, Groups & PSC Exams
Enjoy a smooth online learning experience in various languages at your convenience
113 Programming Languages
procedure P(x,y,z);
Scope
begin y: = y + 1; z: = z + x; end;
begin
Common Data for Questions 65 & 66
a: = 2; b: =3;
P(a+b,a,a); Study the following program written in a
Print (a); block − structured language:
var x,y :integer;
end.
procedure P (n:integer);
begin
64. What is printed by the print statements in the
program P1 assuming call by reference parameter x: = (n+2)/(n−3);
passing? end;
Program P1( ) procedure Q
{ var x,y :integer;
x=10; begin
x: =3;
y=3;
y: =4;
func1(y, x, x);
P(y);
print x;
Write (x) ……………… (1)
print y;
end;
}
begin
func1(x, y, z)
x : =7;
{ y : =8;
y= y + 4; Q:
z= x+ y + z; Write (x) ……………….. (2)
} end;
(a) 10, 3 65. What will be printed by the write statements marked
(b) 31, 3 (1) and (2) in the program if variables are statically
scoped?
(c) 27, 7
(a) 3, 6 (b) 6,7
(d) None of the above
(c) 3, 7 (d) None
Then the output of the program is: 72. Consider the following program
(a) 0.125 0.125 Program P2
(b) 0.25 0.25 var n: int;
(c) 0.25 0.125 procedure W(var x: int)
(d) 0.125 0.25 begin
x=x+1;
71. Consider the following program in pseudo-Pascal print x;
syntax. end
program main procedure D
begin
var x: integer;
var n: int;
procedure Q (z: integer);
n=3;
begin W(n);
z: = z + x; end
writeln(z) begin \\begin P2
end; n = 10;
procedure P (y: integer); D;
var x: integer;
end;
begin
If the language has dynamic scoping and parameters
x: = y + 2; are passed by reference, what will be printed by the
Q(x); program?
writeln(x) (a) 10 (b) 11
end; (c) 3 (d) None of the above
begin
x:=5; 73. Consider the program given below, in a block-
P(x); structured pseudo-language with lexical scoping
and nesting of procedures permitted
Q(x);
Program main;
writeln(x)
end. var …
India’s Best Online Coaching Platform for GATE, ESE, PSUs, SSC-JE, RRB-JE, SSC, Banks, Groups & PSC Exams
Enjoy a smooth online learning experience in various languages at your convenience
117 Programming Languages
11. (c) 12. 3 13. (c) 14. (c) 15. (b) 16. (d) 17. (d) 18. (b) 19. (d) 20. 51
21. (a) 22. (c) 23. (d) 24. (c) 25. (d) 26. (d) 27. 230 28. (a) 29. (d) 30. (a)
31. (c) 33. (a) 34. (a) 35. (d) 36. (c) 37. (b) 38. (d) 39. (c) 40. (d) 41. –5
42. (a) 43. (d) 44. 15 45. (c) 46. 1, 40 47. 2016 48. 30 49. 3 50. (a) 51. (b)
52. (b) 53. (d) 54. (b) 55. (a) 56. (a) 57. (b) 58. (d) 59. (d) 60. (b) 64. (b)
65. (a) 66. (b) 70. (c) 71. (A) 12, 7, 10, 5 (B) 14, 14, 10, 10 72. (d) 73. (d) 74. (d)
75. (b) 76. (c) 77. (c), (d) 78. (a), (b) & (d) 79. (a), (b) & (d)
Regular Live Doubt clearing Sessions | Free Online Test Series | ASK an expert
Affordable Fee | Available 1M | 3M | 6M |12M|18M and 24 Months Subscription Packages