C Programming GATE CS and IT previous year questions with Answer
Ques 11 Gate 2019
Consider the following C program:
int jumble(int x, int y) {
x = 2 * x + y;
return x;
}
int main() {
int x = 2, y = 5;
y = jumble(y, x);
x = jumble(y, x);
printf("%d ", x);
return 0;
}
The value printed by program is __________
a is the correct answer.
Ques 12 Gate 2019
Consider the following C program:
int r(){
int static num=7;
return num--;
}
int main() {
for(r();r();r()) {
printf("%d ",r());
};
return 0;
}
Ques 13 Gate 2019
Consider the following C program:
if (n < 0)
printf(“ % d”, n);
else {
convert(n / 2);
printf(“ % d”, n % 2);
}
}
Ques 14 Gate 2018
Consider the following program written in pseudo-code. Assume that x and y are integers.
if (y !=1 ) {
if (x !=1) {
print("*");
Count (x/2, y);
}
else {
y=y-1;
Count (1024, y);
}
}
}
The number of times that the print statement is executed by the call Count(1024, 1024) is _______ .
a is the correct answer.
Ques 15 Gate 2018
Consider the following C program:
int counter = 0;
int calc(int a, int b) {
int c;
counter++;
if (b == 3)
return (a * a * a);
else {
c = calc(a, b / 3);
return (c * c * c);
}
}
int main() {
calc(4, 81);
printf("%d", counter);
}
The output of this program is ________ .
a is the correct answer.
Ques 16 Gate 2018
Consider the following C code. Assume that unsigned long int type length is 64 bits.
unsigned long int i, j = 0, sum = 0;
for( i = n; i > 1; i = i/2) j++;
for( ; j > 1; j = j/2) sum++;
return sum;
}
The value returned when we call fun with the input 240 is
Ques 17 Gate 2018
Consider the following C program.
struct Ournode {
char x, y, z;
};
int main() {
struct Ournode p = {'1', '0', 'a' + 2};
struct Ournode *q = &p;
printf("%c, %c", *((char *)q + 1), *((char *)q + 2));
return 0;
}
The output of this program is:
Ques 18 Gate 2017 Set-2
Consider the C program fragment below which is meant to divide x by y using repeated subtractions. The variable x, y, q and r are all unsigned int.
{
r = r - y;
q = q + 1;
}
Which of the following conditions on the variables x, y, q and r before the execution of the fragment will ensure that the loop terminates in a state satisfying the condition x == (y*q + r)?
Ques 19 Gate 2017 Set-2
Consider the following function implemented in C:
{
int *ptr;
x = 0;
ptr = &x;
y = *ptr;
*ptr = 1;
printf("%d,%d", x, y);
}
The output of the printxy(1,1) is
Ques 20 Gate 2017 Set-1
The output of executing the following C program is ________.
int total(int v)
{
static int count = 0;
while (v) {
count += v & 1;
v >>= 1;
}
return count;
}
void main()
{
static int x = 0;
int i = 5;
for (; i> 0; i--) {
x = x + total(i);
}
printf (“%dn”, x) ;
}
a is the correct answer.