A highly popular method used to prepare for the GATE Exam is to practise all the previous years’ GATE Questions to perfection. Candidates can practise, analyse and understand concepts while solving them. It will also help you strengthen your time management skills. We have attempted to compile, here in this article, a collection of GATE Questions on C programming.
Candidates are urged to practise these C programming GATE previous year questions to get the best results. C programming is an important topic in the GATE CSE question paper, and solving these questions will help the candidates to prepare more proficiently for the GATE exams. Meanwhile, candidates can find the GATE Questions for C programming here, in this article below, to solve and practise before the exams. They can also refer to these GATE previous year question papers and start preparing for the exams.
GATE Questions on C Programming
- struct node
-
-
- An array, each element of which is pointer to a structure of type node
- A structure of 2 fields, each field being a pointer to an array of 10 elements
- A structure of 3 fields: an integer, a float, and an array of 10 elements
- An array, each element of which is a structure of type node
-
- The number of tokens in
-
-
- 3
- 10
- 25
- 22
-
- Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment
-
-
- 22 bytes
- 18 bytes
- 14 bytes
- 10 bytes
-
- Consider the given three C functions: [P1] int * g (void)
-
-
- Only P1 and P2
- Only P3
- Only P1 and P3
- P1, P2, and P3
-
- What does the given program print?
-
-
- GATE 2011
- 2011
- E2011
- 011
-
- The output of the following C program is__________
-
-
- -5
- 6
- -6
- 0
-
- The following program prints ___________
-
-
- 2 2
- 2 1
- 0 1
- 0 2
-
- Consider the following C program
-
-
- f(s,*s)
- i = f(i,s)
- f(i,*s)
- f(i,*p)
-
- The output of the following C program is
-
-
- 0, c
- 0, a+2
- ‘0’, ‘a+2’
- ‘0’,’c’
-
- The output of the following C program is
-
-
- 2016
- 2018
- 016
- 16
-
- The output of the following C program is
-
-
- 6
- 5
- 66
- 0
-
- The most appropriate matching for the following pairs
-
-
- X-1 Y-3 Z-2
- X-2 Y-1 Z-3
- X-3 Y-2 Z-1
- X-3 Y-1 Z-2
-
- Consider the following C function
-
-
- call swap (x,y)
- call swap (&x, &y)
- swap (x, y) cannot be used as it does return any value
- swap (x,y) cannot be used as the parameters are passed by value
-
- Assume the following C variable declaration
-
-
- I, II and IV
- II, III and IV
- II and IV
- IV only
-
- In the C language
-
-
- There is no such restriction in C language
- True
- False. In C, variables are statically scoped, not dynamically
- False. The activation records are stored on the same stack
-
- Consider the following C program:
-
-
- 26
- 25
- 20
- 0
-
- Consider the following C program:
-
-
- 6
- 7
- 8
- 0
-
- Consider the following C function.
-
-
- It will print the binary representation of n and terminate
- It will print the binary representation of n in the reverse order and terminate
- It will print the binary representation of n but will not terminate
- It will not print anything and will not terminate
-
- Consider the following C program:
-
-
- 41
- 52
- 63
- 630
-
- Consider the following C program:
-
-
- 0
- 5
- 1
- None of the above
-
- Consider the following C program:
-
-
- 10
- 12
- 15
- 20
-
- Consider the following C program:
-
-
- Hi Bye Bye Hi
- Hi Bye Hi Bye
- Bye Hi Hi Bye
- Bye Hi Bye Hi
-
- Consider the following C code. Assume that unsigned long int type length is 64 bits.
-
-
- 4
- 5
- 6
- 40
-
- Consider the following C program
-
-
- 3
- 5
- 7
- 9
-
- The output of executing the following C program is ____________ .
-
-
- 23
- 25
- 27
- 29
-
- Consider the following function implemented in C:
-
-
- 0, 0
- 0, 1
- 1, 0
- 1, 1
-
- Consider the C program fragment below which is meant to divide x by y using repeated subtraction. The variables x, y, q and r are all unsigned int.
-
-
- (q == r) && (r == 0)
- (x > 0) && (r == x) && (y > 0)
- (q == 0) && (r == x) && (y > 0)
- (q == 0) && (y > 0)
-
- Consider the following snippet of a C program. Assume that swap(&x, &y) exchanges the contents of x and y.
-
-
- 3
- 4
- 5
- 6
-
- Consider the following C program.
-
-
- 0
- 1
- 5
- None of the above
-
- What will be the output of the following C program?
-
-
- 3 1 2 2 1 3 4 4 4
- 3 1 2 1 1 1 2 2 2
- 3 1 2 2 1 3 4
- 3 1 2 1 1 1 2
-
{
int i;
float j;
};
struct node *s[10];
The above C declaration defines
GATE CSE 2000
Answer (a)
printf(“i = %d, &i – %x”, i, &i);
GATE CSE 2000
Answer (b)
GATE CSE 2000
struct {
short s [5];
union {
float y;
long z;
}u;
} t;
Answer (b)
{
int x = 10;
return (&x);
}
[P2] int * g (void){
int * px;
*px = 10;
return px;
}
[P3] int * g (void){
int * px
px = (int *) malloc (sizeof(int));
*px = 10;
return px;
}
Which of the above three functions are likely to cause problems?
GATE CSE 2001
Answer (a)
char c[ ] = “GATE2011”
char *p = c;
printf (“%s”, p + p[3] – p[1]);
GATE CSE 2011
Answer (b)
GATE CSE 2015 Set 1
void f1(int a, int b) {
int c;
c=a; a=b; b=c;
}
void f2(int *a, int *b) {
int c;
c=*a; *a=*b; *b=c;
}
int main(){
int a=4, b=5, c=6;
f1(a,b);
f2(&b, &c);
printf(“%d”,c-a-b);
}
Answer (a)
#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);
return 0;
}
GATE CSE 2010
Answer (d)
void f(int, short);
void main()
{
int i = 100;
short s = 12;
short *p = &s;
__________ ; // call to f()
}
Which one of the following expressions, when placed in the blank above, will NOT result in a type checking error?
GATE CSE 2016 Set 1
Answer (d)
GATE CSE 2018
#include< stdio.h >
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;
}
Answer (a)
#include < stdio.h >
void mystery(int *ptra, int *ptrb) {
int *temp;
temp = ptrb;
ptrb = ptra;
ptra = temp;
}
int main() {
int a=2016, b=0, c=4, d=42;
mystery(&a, &b);
if (a < c)
mystery(&c, &a);
mystery(&a, &d);
printf(“%d\n”, a);
}
GATE CSE 2016 Set 1
Answer (a)
#include < stdio.h >
int main () {
int arr [] = {1,2,3,4,5,6,7,8,9,0,1,2,5}, *ip = arr+4;
printf (“%d\n”, ip[1]);
return 0;
}
GATE CSE 2019
Answer (a)
X: m=malloc(5); m= NULL;
Y: free(n); n->value = 5;
Z: char *p; *p=’a’;
1: using dangling
2: using uninitialized pointers
3. lost memory
is:
GATE CSE 2000
Answer (d)
GATE CSE 2004
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
Answer (d)
int * A[10], B[10][10];
Of the following expressions
I. A[2]
II. A[2] [3]
III. B[1]
IV. B[2] [3]
Which will not give compile-time errors if used as left-hand sides of assignment statements in a C program?
GATE CSE 2003
Answer (a)
a) At most one activation record exists between the current activation record and the activation record for the main
b) The number of activation records between the current activation record and the activation record for the main depends on the actual function calling sequence.
c) The visibility of global variables depends on the actual function calling sequence.
d) Recursion requires the activation record for the recursive function to be saved on a different stack before the recursive function can be called.
GATE CS 2002
Answer (b)
#include <stdio.h>
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 \n”, x);
return 0;
}
The value printed by the program is _____
(GATE 2019)
Answer (a)
#include <stdio.h>
int main(){
int arr[]={1,2,3,4,5,6,7,8,9,0,1,2,5}, *ip=arr+4;
printf(“%d\n”, ip[1]);
return 0;
}
The number that will be displayed on execution of the program is _______
(GATE 2019)
Answer (a)
void convert(int n){
if(n<0)
printf(“%d”,n);
else {
convert(n/2);
printf(“%d”,n%2);
}
}
Which one of the following will happen when the function convert is called with any positive integer n as an argument?
(GATE 2019)
Answer (d)
#include <stdio.h>
int r(){
static int num=7;
return num–;
}
int main(){
for (r();r();r())
printf(“%d”,r());
return 0;
}
Which one of the following values will be displayed on execution of the programs?
(GATE 2019)
Answer (b)
#include <stdio.h>
int main(){
float sum = 0.0, j = 1.0, i = 2.0;
while (i/j > 0.0625){
j = j + j;
sum = sum + i/j;
printf(“%f\n”, sum);
}
return 0;
}
The number of times the variable sum will be printed, when the above program is executed, is _________
(GATE 2019)
Answer (b)
#include <stdio.h>
int main()
{
int a[ ] = {2, 4, 6, 8, 10};
int i, sum = 0, *b = a + 4;
for (i = 0; i < 5; i++)
sum = sum + (*b – i) – *(b – i);
printf (“%d\n”, sum);
return 0;
}
The output of the above C program is ______
(GATE 2019)
Answer (a)
#include<stdio.h>
void fun1(char *s1, char *s2){
char *tmp;
tmp = s1;
s1 = s2;
s2 = tmp;
}
void fun2(char **s1, char **s2){
char *tmp;
tmp = *s1;
*s1 = *s2;
*s2 = tmp;
}
int main(){
char *str1 = “Hi”, *str2 = “Bye”;
fun1(str1, str2); printf(“%s %s “, str1, str2);
fun2(&str1, &str2); printf(“%s %s”, str1, str2);
return 0;
}
The output of the program above is
(GATE 2018)
Answer (a)
unsigned long int fun(unsigned long int n){
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
(GATE 2018)
Answer (a)
#include <stdio.h>
#include <string.h>
void printlength (char *s, char *t) {
unsigned int c=0;
int len = ((strlen(s) – strlen(t)) > c) ? strlen(s): strlen(t);
printf(“%d\n”,len);
}
void main () {
char *x = “abc”,
char *y = “defgh”;
printlength (x,y);
}
Recall that strlen is defined in string. h as returning a value of type size_t, which is an unsigned int. The output of the program is _____
(GATE 2017)
Answer (a)
#include <stdio.h>
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(“%d\n”,x);
}
(GATE 2017)
Answer (a)
void printxy(int x, int y) {
int *ptr;
x=0;
ptr=&x;
y=*ptr;
*ptr=1;
printf(“%d, %d”, x, y);
}
The output of invoking printxy(1,1) is
(GATE 2017)
Answer (c)
while (r >=y) {
r = r – y;
q = q + 1;
}
Which of the following condition 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)?
(GATE 2017)
Answer (c)
int main () {
int array[] = {3,5,1,4,6,2};
int done = 0;
int i;
while (done == 0) {
done = 1;
for (i = 0, i<=4; i++) {
if (array[i]< array[i+1]) {
swap (&array[i], &array[i+1]);
done = 0;
}
}
for (i=5; i>=1; i–) {
if (array[i] > array [i-1]) {
swap(&array[i], &array[i-1]);
done = 0;
}
}
printf(“%d”, array[3]);
}
The output of the program is ______
(GATE 2017)
Answer (a)
#include<stdio.h>
int main () {
int m = 10;
int n, nl;
n = ++m;
n1 = m++;
n–;
–n1;
n-= n1;
printf (“%d”,n),
return 0;
}
The output of the program is _________
(GATE 2017)
Answer (a)
void count(int n){
static int d=1;
printf(“%d “, n);
printf(“%d “, d);
d++;
if(n>1) count(n-1);
printf(“%d “, d);
}
void main(){
count(3);
}
(GATE 2016)
Answer (a)
Keep learning and stay tuned to get the latest updates on the GATE Syllabus for CSE (Computer Science Engineering), Introduction to C Programming, GATE CSE Question Paper, and more.
Comments