5 Most Tricky Gate Questions in Programming

GATE CS plays a valuable role for students who want to get hired by PSU’s or to get admission in IIT’S, NIT for further studies.

Right! 😎

Is it your dream to crack Gate?

Like Gate questions on Recursion or Pointer, I come up with the 5 most tricky Gate questions in programming with step-by-step clarification on each question.

Let’s dive into it!

Question 1: (GATE 2000: 2 Marks)

The value of j at the end of the execution of the following C program is __

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)
}
  1. 10
  2. 4
  3. 6
  4. 7
Gate Programming Q1

Question 2: (GATE 2004: 2 Marks)

What is the output of the following program?

#include<stdio.h>
int funcf(int x);
int funcg(int y);
main()
{
int x=5, y=10, count;
for(count=1; count<=2; ++count)
{
y+=funcf(x)+funcg(x);
printf("%d",y);
}}
funcf(int x)
{
int y;
y=funcg(x);
return(y);
}
funcg(int x)
{
static int y=10;
y+=1;
return(y+x);
}
  1. 43 80
  2. 42 74
  3. 33 37
  4. 32 32
Gate Programming Q2

Question 3: (GATE 2004: 2 Marks)

Consider the following C program segment:

char p[20];
char *s="string";
int length=strlen(s);
for(i=0;i<length;i++)  
 p[i]=s[length-i];
printf("%s",p);

The output of the program is

  1. gnirts
  2. string
  3. gnirt
  4. no output is printed
Gate Programming Q3

Question 4: (GATE 2006: 2 Marks)

Which one of the choices given below would be printed when the following program is executed?

#include<stdio.h>
int a1[]={6,7,8,18,34,67};
int a2[]={23,56,28,29};
int a3[]={-12,27,-31};
int *x[]={a1,a2,a3};
void print(int *a[])
{
printf("%d,",a[0][2]);
printf("%d,",*a[2]);
printf("%d,",*++a[0]);
printf("%d,",*(++a)[0]);
printf("%d\n",a[-1][+1]);
}
main()
{
print(x);
}
  1. 8, -12, 7, 23, 8
  2. 8, 8, 7, 23, 7
  3. -12, -12, 27, -31, 23
  4. -12, -12, 27, -31, 56

Question 5: (GATE 2010: 2 Marks)

What is the value printed by the following C program?

#include<stdio.h>
int f(int *a, int n)
{
if(n<=0) return 0;
else if(*a%2==0)
 return *a+f(a+1, n-1);
else return *a-f(a+1, n-1);
}
int main()
{
int a[]={12, 7, 13, 4, 11, 6};
printf("%d",f(a,6));
return 0;
}
  1. -9
  2. 5
  3. 15
  4. 19
Gate Programming Q5

Wrapping it Up!

Sometimes, it becomes very difficult to find a step-by-step solution to a program. So, I tried to help you to solve the GATE questions in programming.

I hope, you liked this post, and if you have any related suggestions or queries, feel free to let me know.👇

Leave a Reply

Your email address will not be published. Required fields are marked *