0% found this document useful (0 votes)
20 views

5 8 2024-Gate

Uploaded by

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

5 8 2024-Gate

Uploaded by

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

The number of tokens in the following C

statement is?

printf("i = %d, &i = %x", i, &i);

(a) 3 (b) 26 (c) 10 (d) 21


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

char inchar = 'A';


switch (inchar)
{
case 'A' :
printf ("choice A \n") ; case 'B' :
printf ("choice B ") ; case 'C' :
case 'D' :
case 'E' :
default:
printf ("No Choice") ;
}
a) No choice
b) Choice A
c) Choice A Choice B No choice
d) Program gives no output as it is erroneous
Consider the following C function definition:
int Trial (int a, int b, int c)
{
if ((a > = b) && (c < b)) return b; else if (a > = b)
return Trial (a,c,b); else return Trial (b,a,c);
}
The function Trial:
a) Finds the maximum of a, b, and c
b) Finds the minimum of a, b and c
c) Finds the middle number of a, b, c
d) None of the above
The value of j at the end of the execution of the following
C program.

int incr (int i)


{
static int count = 0; count = count + i; return (count);
}
main ()
{
int i,j;
for (i = 0; i <=4; i++) j = incr(i);
}
(a) 10 (b) 4 (c)6 (d) 7
Consider the following declaration of a ‘two-
dimensional array in C: char a[100][100];
Assuming that the main memory is byte-
addressable and that the array is stored
starting from memory address 0, the address
of a[40][50] is

(a) 4040 (b) 4050 (c) 5040 (d) 5050


Consider the following C-program:
void foo(int n, int sum)
{
int k = 0, j = 0;
if (n == 0) return;
k = n % 10; j = n / 10; sum = sum + k;
foo (j, sum); printf ("%d,", k);
}
int main ()
{
int a = 2048, sum = 0; foo (a, sum);
printf ("%d\n", sum); getchar();
}
What does the above program print?
(a) 8, 4, 0, 2, 14
(b) 8, 4, 0, 2, 0
(c) 2, 0, 4, 8, 14
(d) 2, 0, 4, 8, 0
Consider the following C function:
int f(int n)
{
static int i = 1; if (n >= 5) return n;
n = n+i; i++;
return f(n);
}
The value returned by f(1) is
(a) 5 (b) 6 (c) 7 (d) 8
Consider the following C program
void 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 & y
D. the least common multiple of x & y
Consider the following C-program: double foo (double); /* Line 1 */
int main () { double da, db;
// input da

db = foo (da);
}
double foo (double a) { return a;
}
The above code compiled without any error or warning. If Line 1 is
deleted, the above code will show:
A. no compile warning or error
B. some compiler-warnings not leading to unintended results
C. some compiler-warnings due to type-mismatch eventually
leading to unintended results
D. compiler errors
Consider line number 3 of the following C-program.
int main ( ) { /* Line 1 */
int i, n; /* Line 2 */
fro (i =0, i<n, i++); /* Line 3 */
}
Identify the compiler’s response about this line
while creating the object-module:
A. No compilation error
B. Only a lexical error
C. Only syntactic errors
D. Both lexical and syntactic errors
Consider these two functions and two statements S1 and S2 about them.
int work1(int *a, int i, int j)
{
int x = a[i+2]; a[j] = x+1; return a[i+2] - 3;
}
int work2(int *a, int i, int j)
{
int t1 = i+2; int t2 = a[t1]; a[j] = t2+1; return t2–3;
}
S1: The transformation from work1 to work2 is valid, i.e., for any program state and
input arguments, work2 will compute the same output and have the same effect
on program state as work1
S2: All the transformations applied to work1 to get work2 will always improve the
performance (i.e reduce CPU time) of work2 compared to work1

A. S1 is false and S2 is false


B. S1 is false and S2 is true
C. S1 is true and S2 is false
D. S1 is true and S2 is true
Consider the following C function:
int f(int n)
{
static int r = 0;
if (n <= 0) return 1; if (n > 3)
{
r = n;
return f(n-2)+2;
}
return f(n-1)+r;
}
What is the value of f(5) ?
(a) 5 (b) 7 (c)9 (d) 18
Consider the following recursive C function that
takes two arguments
unsigned int foo(unsigned int n, unsigned int r)
{
if (n > 0) return (n%r + foo (n/r, r )); else return 0;
}
What is the return value of the function foo
when it is called as foo(345, 10) ?
(a) 345 (b) 12 (c) 5 (d) 3
Consider the following recursive C function that
takes two arguments

unsigned int foo(unsigned int n, unsigned int r) {


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

What is the return value of the function foo when it


is called as

foo(513, 2)?
(a) 9 (b) 8 (c) 5 (d) 2
The following C declaration
struct node
{
int i; float j;
};
struct node *s[10] ; define s to be

A. An array, each element of which is a pointer to a structure of


type node
B. A structure of 2 fields, each field being a pointer to an array
of 10 elements
C. A structure of 3 fields: an integer, a float, and an array of 10
elements
D. An array, each element of which is a structure of type node.
Consider the following C function
void swap (int a, int b)
{
int temp; temp = a; a = b;
b = temp;
}
In order to exchange the values of two variables x and y.
A. call swap (x, y)
B. call swap (&x, &y)
C. swap (x, y) cannot be used as it does not return any
value
D. swap (x, y) cannot be used as the parameters are passed
by value
What does the following C-statement declare?
int ( * f) (int * ) ;

A. A function that takes an integer pointer as


argument and returns an integer
B. A function that takes an integer as argument
and returns an integer pointer
C. A pointer to a function that takes an integer
pointer as argument and returns an integer.
D. A function that takes an integer pointer as
argument and returns a function pointer
What does the following program print?

#include<stdio.h>
void f(int *p, int *q)
{
p = q;
*p = 2;
}
int i = 0, j = 1; int main()
{
f(&i, &j);
printf("%d %d \n", i, j); getchar();
return 0;
}

(a) 2 2 (b) 2 1 (c)0 1 (d) 0 2


What does the following fragment of C-
program print?

char c[] = "GATE2011";


char *p =c;
printf("%s", p + p[3] - p[1]);

(a) GATE2011 (b) E2011 (c) 2011 (d) 011


Consider the following recursive C function.
void get (int n)
{
if (n < 1) return; get (n–1);
get (n–3); printf ("%d", n);
}
If get(6) function is being called in main( ) then how many
times will the get() function be invoked before returning
to the main( )?
A. 15
B. 25
C. 35
D. 45
Consider the following function written in the C programming
language.
void foo (char *a)
{
if (*a && *a != ` `)
{
foo (a+1); putchar (*a);
}
}
The output of the above function on input “ABCD EFGH” is

A. ABCD EFGH
B. ABCD
C. HGFE DCBA
D. DCBA

You might also like