0% found this document useful (0 votes)
19 views20 pages

GATE Questions On C Programming

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

GATE Questions On C Programming

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

17/11/2025, 11:41 GATE Questions on C Programming - Testbook.

com

Overview Test Series

Home GATE GATE Questions on C Programming - Testbook.com

GATE Questions on C Programming - Testbook.com

Download As PDF

Practicing previous years’ GATE Questions is a highly effective strategy for preparing for the
GATE Exam
. By solving these questions, candidates can refine their understanding of concepts, improve their analytical
skills, and enhance their time management abilities. This article comprises a collection of GATE Questions
on C programming, compiled for your convenience. We strongly recommend candidates to practice these
C programming GATE previous year questions to achieve the best results. C programming is a crucial topic
in the GATE CSE question paper, and practicing these questions will allow the candidates to prepare more
proficiently for the GATE exams. Below, in this article, you can find the GATE Questions for C programming
for your practice. You can also refer to these
GATE previous year question papers
for your exam preparation.

GATE Questions on C Programming

Consider the following C declaration:

struct node {
int i;
float j;
};
struct node *s[10];

This C declaration in the GATE CSE 2000 exam defined:


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

Answer: (a) The number of tokens in the following printf statement from the GATE CSE 2000 exam:

printf(“i = %d, &i – %x”, i, &i);

https://testbook.com/gate/c-programming-gate-questions 1/20
17/11/2025, 11:41 GATE Questions on C Programming - Testbook.com

3
Overview Test Series
10
25
22

Answer: (b) For the given C code from the GATE CSE 2000 exam, assuming 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 is:

struct {
short s [5];
union {
float y;
long z;
}u;
} t;

22 bytes
18 bytes
14 bytes
10 bytes

Answer: (b) Consider the following three C functions from the GATE CSE 2001 exam:

[P1] int * g (void) {


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?


Only P1 and P2
Only P3
Only P1 and P3
P1, P2, and P3

Answer: (a) For the following C program from the GATE CSE 2011 exam, what does it print?

https://testbook.com/gate/c-programming-gate-questions 2/20
17/11/2025, 11:41 GATE Questions on C Programming - Testbook.com

char c[] = “GATE2011”


Overview Test Series
char *p = c;
printf (“%s”, p + p[3] – p[1]);

GATE 2011
2011
E2011
011

Answer: (b) Continuing with more C programming questions, the output of the following C program from
the GATE CSE 2015 Set 1 exam is:

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);
}

-5
6
-6
0

Answer: (a) The following program from the GATE CSE 2010 exam prints:

#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;
}

22
21

https://testbook.com/gate/c-programming-gate-questions 3/20
17/11/2025, 11:41 GATE Questions on C Programming - Testbook.com

01
Overview Test Series
02

Answer: (d) The given C program from the GATE CSE 2016 Set 1 exam:

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?
f(s,*s)
i = f(i,s)
f(i,*s)
f(i,*p)

Answer: (d) The output of the following C program from the GATE CSE 2018 exam is:

#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;
}

0, c
0, a+2
‘0’, ‘a+2’
‘0’,’c’

Answer: (a) The output of the following C program is:

#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;
https://testbook.com/gate/c-programming-gate-questions 4/20
17/11/2025, 11:41 GATE Questions on C Programming - Testbook.com

mystery(&a, &b);
Overview Test Series
if (a < c)
mystery(&c, &a);
mystery(&a, &d);
printf(“%d\n”, a);
}

2016
2018
016
16

Answer: (a) The output of the following C program is:

#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;
}

6
5
66
0

Answer: (a) The most appropriate matching for the following pairs in the GATE CSE 2000 exam:

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

X-1 Y-3 Z-2


X-2 Y-1 Z-3
X-3 Y-2 Z-1
X-3 Y-1 Z-2

Answer: (d) Consider the following C function from the GATE CSE 2004 exam:

void swap (int a, int b) {


int temp;
temp = a;
a = b;
b = temp;
}

https://testbook.com/gate/c-programming-gate-questions 5/20
17/11/2025, 11:41 GATE Questions on C Programming - Testbook.com

In order to exchange the values of two variables x and y:


Overview Test Series
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

Answer: (d) Assume the following C variable declaration from the GATE CSE 2003 exam:

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?
I, II and IV
II, III and IV
II and IV
IV only

Answer: (a) In the C language, according to the GATE CS 2002 exam:


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.

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

Answer: (b) Consider the following C program:

#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);
https://testbook.com/gate/c-programming-gate-questions 6/20
17/11/2025, 11:41 GATE Questions on C Programming - Testbook.com

printf(“%d \n”, x);


Overview Test Series
return 0;
}

The value printed by the program is ____ (GATE 2019)


26
25
20
0

Answer: (a) Consider the following C program:

#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)
6
7
8
0

Answer: (a) Consider the following C function.

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)
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

Answer: (d) Consider the following C program:

#include <stdio.h>
void f (int *p, int *q) {
p = q;
*p = 2;

https://testbook.com/gate/c-programming-gate-questions 7/20
17/11/2025, 11:41 GATE Questions on C Programming - Testbook.com

}
Overview Test Series
int i = 0, j = 1;
int main ( ){
f(&i, &j);
printf (“%d %d \ n”, i, j);
return 0;
}

Which one of the following values will be displayed on execution of the programs? (GATE 2019)
22
21
01
02

Answer: (d) Consider the following C program:

#include <stdio.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 2019)
3
5
7
9

Answer: (a) Consider the following C program:

#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 output of the above C program is ______ (GATE 2019)


6
5
66

https://testbook.com/gate/c-programming-gate-questions 8/20
17/11/2025, 11:41 GATE Questions on C Programming - Testbook.com

0
Overview Test Series

Answer: (a) The most appropriate matching for the following pairs:

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

(GATE 2019)
X-1 Y-3 Z-2
X-2 Y-1 Z-3
X-3 Y-2 Z-1
X-3 Y-1 Z-2

Answer: (d) 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:


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

Answer: (d) Assume the following C variable declaration:

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?
I, II and IV
II, III and IV
II and IV
IV only

https://testbook.com/gate/c-programming-gate-questions 9/20
17/11/2025, 11:41 GATE Questions on C Programming - Testbook.com

Answer: (a) In the C language:


Overview Test Series
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.

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

Answer: (b) Consider the following C program:

#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 ____


26
25
20
0

Answer: (a) Consider the following C program:

#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 _______


6
7
8

https://testbook.com/gate/c-programming-gate-questions 10/20
17/11/2025, 11:41 GATE Questions on C Programming - Testbook.com

0
Overview Test Series

Answer: (a) Consider the following C function.

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?
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

Answer: (d) Consider the following C program:

#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;
}

Which one of the following values will be displayed on execution of the programs?
22
21
01
02

Answer: (d) Consider the following C program:

#include <stdio.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 () {
https://testbook.com/gate/c-programming-gate-questions 11/20
17/11/2025, 11:41 GATE Questions on C Programming - Testbook.com

char *x = “abc”,
Overview Test Series
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 _____
3
5
7
9

Answer: (a) Consider the following C program:

#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 output of the above C program is ______


6
5
66
0

Answer: (a) The most appropriate matching for the following pairs:

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

X-1 Y-3 Z-2


X-2 Y-1 Z-3
X-3 Y-2 Z-1
X-3 Y-1 Z-2

Answer: (d) Consider the following C function:

void swap (int a, int b) {


int temp;
temp = a;
a = b;
b = temp;
}

https://testbook.com/gate/c-programming-gate-questions 12/20
17/11/2025, 11:41 GATE Questions on C Programming - Testbook.com

In order to Test
Overview exchange
Series the values of two variables x and y:
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

Answer: (d) Assume the following C variable declaration:

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?
I, II and IV
II, III and IV
II and IV
IV only

Answer: (a) In the C language:


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.

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

Answer: (b) Continue learning and stay tuned for the latest updates on the
GATE Syllabus for CSE (Computer Science Engineering)
,
Introduction to C Programming
,
GATE CSE Question Paper
, and more

More Articles for GATE

https://testbook.com/gate/c-programming-gate-questions 13/20
17/11/2025, 11:41 GATE Questions on C Programming - Testbook.com

Closure
Overview Properties
Test Series of Context-Free Languages (CFLs)

Classification of Context Free Grammars for GATE CSE Exam

Cluster File Organization in DBMS - Types, Pros & Cons

Understanding Codd’s Rules in DBMS | Testbook.com

Code Optimization in Compiler Design - Testbook.com

Learn About Cache Mapping Techniques for CSE - Testbook.com

Can 3rd Year Students Apply for GATE Exam? | Testbook.com

Can we do GATE After 12th? - Testbook.com

Government Jobs through GATE Exam - Testbook.com

Cartesian Join in SQL - A Comprehensive Guide | Testbook.com

Frequently Asked Questions

What is the importance of practicing GATE Questions on C Programming?

Where can I find GATE previous year question papers for C programming?

Does the article provide solutions to the GATE Questions on C Programming?

Crack AE & JE Civil Exam with


India's Super Teachers
Get 6 Months AE & JE + PYP/MCQ Book
(Civil) SuperCoaching @ just

₹11399 ₹4769

Your Total Savings ₹6630

Purchase Now

https://testbook.com/gate/c-programming-gate-questions 14/20
17/11/2025, 11:41 GATE Questions on C Programming - Testbook.com

Want
Overview toTest
knowSeriesmore about this Super Coaching ? Explore SuperCoaching Now

People also like

AE & JE - Mechanical UGC NET/SET (Hinglish) UPSC Beginners Program

₹11399 (59% OFF) ₹31999 (59% OFF) ₹50000 (100% OFF)

₹4769 (Valid for 6 Months) ₹13416 (Valid till June 2026 Ex ₹0 (Valid for 1 year)

Explore this Supercoaching Explore this Supercoaching Explore this Supercoaching

https://testbook.com/gate/c-programming-gate-questions 15/20
17/11/2025, 11:41 GATE Questions on C Programming - Testbook.com

Overview Test Series

Test Series

https://testbook.com/gate/c-programming-gate-questions 16/20
17/11/2025, 11:41 GATE Questions on C Programming - Testbook.com

131.3k Users 113.1k Users 115.2k Users


Overview Test Series

GATE Mathematics & GATE CSE 2023-24 Test GATE CE 2025-26 Test
General Aptitude (Commo… Series Series
92 Total Tests 129 Total Tests | 1 Free Tests 160 Total Tests | 1 Free Tests

English English English

54 Chapter Test 73 Chapter Test 74 Chapter Test


10 Subject Test 15 Subject Test 26 Subject Test
28 Previous Year Paper 7 Full Test 10 Full Test
+34 more tests +50 more tests

View Test Series View Test Series View Test Series

View More
Report An Error

Important Links for GATE Exam

GATE Eligibility Criteria GATE Exam Pattern


GATE Cut Off for IIT GATE COAP

GATE Application Process GATE Preparation Tips


Opportunities after GATE PSU Through GATE

Super Coaching

GATE mechanical Coaching GATE electrical Coaching


GATE ece Coaching AE JE electrical Coaching

GATE civil Coaching GATE cse Coaching


AE JE mechanical Coaching AE JE civil Coaching

Branch wise Page

GATE Architecture and Planning GATE Aerospace Engineering

https://testbook.com/gate/c-programming-gate-questions 17/20
17/11/2025, 11:41 GATE Questions on C Programming - Testbook.com

GATE Agricultural Engineering GATE Metallurgical Engineering


Overview Test Series
GATE Chemical Engineering GATE Chemistry
GATE CS GATE Physics
GATE Naval Architecture & Marine Engineering GATE Environmental Science & Engineering
GATE Statistics GATE Textile Engineering and Fibre Science
GATE Mining Engineering GATE Geology and Geophysics Engineering

GATE Biomedical Engineering GATE Biotechnology


GATE IN GATE PI
GATE EC GATE EE
GATE Mathematics GATE Geomatics Engineering
GATE Humanities And Social Sciences GATE Life Sciences
GATE Engineering Sciences GATE Petroleum Engineering
GATE Ecology and Evolution

Test Series

GATE CSE Mock Test GATE Chemistry Mock Test


GATE EE Mock Test GATE Mathematics & General Aptitude Mock Test

GATE CE Mock Test GATE IN Mock Test


GATE ECE Mock Test GATE Production & Industrial Engineering (PI) Mock
Test

Previous Year Papers

GATE CS Previous Year Papers GATE Chemistry Previous Year Papers


GATE EE Previous Year Papers GATE ME Previous Year Papers
GATE CH Previous Year Papers GATE Physics Previous Year Papers
GATE Environmental Science & Engineering Previous GATE Statistics Previous Year Papers
Years Papers GATE Aerospace Engineering Previous Years Papers
GATE Geomatics Engineering Previous Year Papers GATE Metallurgical Engineering Previous Year Papers
GATE Architecture and Planning Previous Year Papers GATE Engineering Sciences Previous Years Papers
GATE Ecology and Evolution Previous Years Papers GATE 2019 Question Papers
GATE 2020 Question Papers GATE 2015 Question Papers
GATE 2016 Question Papers
GATE 2012 Question Papers

GATE CE Previous Year Papers GATE IN Previous Year Papers


GATE EC Previous Year Papers GATE PI Previous Year Papers
GATE Humanities And Social Sciences Previous Year GATE Biomedical Engineering Previous Years Papers
Papers GATE Life Sciences Previous Year Papers
GATE Naval Architecture And Marine Engineering GATE Biotechnology Previous Years Papers
Previous Year Papers
https://testbook.com/gate/c-programming-gate-questions 18/20
17/11/2025, 11:41 GATE Questions on C Programming - Testbook.com

GATE Petroleum Engineering Previous Years Papers GATE Textile Engineering and Fibre Science Previous
Overview Test Series
GATE Agricultural Engineering Previous Year Papers Years Papers
GATE 2022 Question Papers GATE 2021 Question Papers
GATE 2018 Question Papers GATE 2017 Question Papers
GATE 2014 Question Papers GATE 2013 Question Papers

Company

About us
Careers We are hiring
Testbook Edu Solutions Pvt. Ltd. Teach Online on Testbook
D- 1, Vyapar Marg, Media
Noida Sector 3, Noida, Sitemap
Uttar Pradesh, India - 201301

[email protected]
Toll Free:
1800 203 0577
Office Hours: 10 AM to 7 PM (all 7 days)

Products Our App

Test Series
Live Tests and Quizzes
Testbook Pass
Online Videos
Practice Follow us on

Live Classes
Blog
Refer & Earn
Books
Exam Calendar
GK & CA
Teacher Training Program
Doubts
Hire from SkillAcademy

Copyright © 2014-2024 Testbook Edu Solutions Pvt. Ltd.: All rights reserved

https://testbook.com/gate/c-programming-gate-questions 19/20
17/11/2025, 11:41 GATE Questions on C Programming - Testbook.com

User Policy Terms Privacy


Overview Test Series

https://testbook.com/gate/c-programming-gate-questions 20/20

You might also like