0% found this document useful (0 votes)
7 views3 pages

1 Basics

Uploaded by

fitecek253
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

1 Basics

Uploaded by

fitecek253
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

BASICS

1. Consider the following C function (GATE-2003)


float f(float x,int y)
{
floatp,s; inti;
for(s=1,p=1,i=1;i<y;i++)
{
p *=x/i;
S +=p;
}
return s;
}
For large values of y, the return value of the function f best approximates
a) xy b) ex c) ln(1 + x) d) xx

2. Consider the following C program (GATE-2004)


main()
{
int x, y, m, n;
scanf ("%d %d", &x, &y);
/* x > 0 and y > 0 */
m = x; n = y;
while (m != n)
{
if(m>n)
m = m - n;
else
n = n - m;
}
printf("%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 yd) the least common multiple of x and y

3. Which combination of the integer variables x, y and z makes the variable a get the value 4 in
the following expression? (GATE-2008)
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

4. What will be the output of the following C program segment? (GATE-2012)


charinchar = '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)Choice A
Choice B No Choice
d)Program gives no output as it is erroneous

5. Consider the function func shown below: (GATE 2014)


intfunc(intnum) {
int count = 0;
while (num) {
count++;
num>>= 1;
}
return (count);
}
The value returned by func(435) is ………………

6. 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?
(GATE 2014)
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;

7. Consider the following C program (GATE 2015)


#inclue<stdio.h>
int main()
{
inti, j, k=0;
j = 2*3 / 4 + 2.0 / 5 + 8 / 5;
k - = --j;
for (i=0; i<5; i++)
{
switch(i+k)
{
case1:
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

8. The attributes of three arithmetic operators in some programming language are given below.
(GATE 2016)
Operator Precedence Associativity Arity
+ High Left Binary
- Medium Right Binary
* Low Left Binary
The value of the expression 2 - 5 + 1 - 7 * 3 in this language
is

9. Consider the following C program: (GATE 2017)


#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

10. The following function computes XY for positive integers X and Y.(GATE 2016)
intexp(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

You might also like