C Programming GATE Questions consists of topics like C introductions, C functions, C unions, C operators, control segments, pointers, strings, variables, C array etc.
Table of Contents
C Programming GATE Questions are asked from topics like loops in C, Hello world, functions, arrays, strings, etc. Students must be thorough with the C programming GATE syllabus before the examination.
C programming is one of the very important topics asked in the GATE exam. Candidates must practice C Programming GATE questions to get good marks in the examination.
C Programming GATE Questions- Download PDF
C Programming GATE Questions commonly appear in the GATE CSE exam and students must practice it to get good scores. Candidates can find the C Programming GATE Questions PDF tabulated below.
Particulars | Download Link |
---|---|
C Programming GATE Questions | Download Now |
Also Read: GATE 2024 Preparation Tips from Toppers & Experts
Top 20+ C Programming GATE Questions with Answers
Students must go through top 30 C programming questions with answers and prepare effectively for their GATE CSE examination. The top 10+ GATE CSE question papers with answers are stated below.
1. Consider the following program:
struct node
{
int i;
float j;
};
struct node *s[10];
The above C declaration defines
- 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)
2. The number of tokens in
printf(“i = %d, &i – %x”, i, &i);
- 3
- 10
- 25
- 22
Answer (b)
Also Check: GATE 2024 Question Paper with Solutions
3. 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
struct {
short s [5];
union {
float y;
long z;
}u;
} t;
- 22 bytes
- 18 bytes
- 14 bytes
- 10 bytes
Answer: (b)
4. Consider the given three C functions:
- [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)
Also Read: GATE Negative Marking 2024
5. What does the given program print?
char c[ ] = “GATE2011”
char *p = c;
printf (“%s”, p + p[3] – p[1]);
- GATE 2011
- 2011
- E2011
- 011
Answer: (b)
6. The output of the following C program 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)
Also Read: GATE Answer Key 2024: Download Memory Based PDF (Out)
7. The following program 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;
}
- 2 2
- 2 1
- 0 1
- 0 2
Answer: (d)
8. Consider the following C program
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)
Also Check: GATE Response Sheet 2024: Dates, Steps to Download PDF
9. The output of the following C program 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)
10. 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)
Also Check: GATE Exam Dress Code 2024
11. 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)
12. Consider the following C program:
#include
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)
Also Check: Compiler Design GATE Questions with Answers
13. Consider the following C program:
#include
int main(){
int arr[]={1,2,3,4,5,6,7,8,9,0,1,2,5}, *ip=arr+4;
printf(“%dn”, ip[1]);
return 0;
}
The number that will be displayed on execution of the program is _______
- 6
- 7
- 8
- 0
Answer (a)
14. 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)
Also Check: GATE Aptitude Questions with Answers
15. Consider the following C program:
#include
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?
- 41
- 52
- 63
- 630
Answer (b)
16. Consider the following C program:
#include
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(“%fn”, sum);
}
return 0;
}
The number of times the variable sum will be printed, when the above program is executed, is _________
- 0
- 5
- 1
- None of the above
Answer (b)
Also Check: Operating System GATE Questions with Answers
17. Consider the following C program:
#include
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 (“%dn”, sum);
return 0;
}
The output of the above C program is ______
- 10
- 12
- 15
- 20
Answer (a)
18. Consider the following C program:
#include
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
- Hi Bye Bye Hi
- Hi Bye Hi Bye
- Bye Hi Hi Bye
- Bye Hi Bye Hi
Answer (a)
Also Check: DBMS GATE Questions with Answers
19. Consider the following C code. Assume that unsigned long int type length is 64 bits.
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
- 4
- 5
- 6
- 40
Answer (a)
20. Consider the following C program:
#include
#include
void printlength (char *s, char *t) {
unsigned int c=0;
int len = ((strlen(s) – strlen(t)) > c) ? strlen(s): strlen(t);
printf(“%dn”,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 _____
- 3
- 5
- 7
- 9
Answer (a)
Also Check: GATE CSE Question Papers 2024
21. The output of executing the following C program is ____________ .
#include
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);
}
- 23
- 25
- 27
- 29
Answer (a)
22. Consider the following function implemented in C:
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
- 0, 0
- 0, 1
- 1, 0
- 1, 1
Answer (c)
Also Check: Important & High Scoring Topics for GATE 2024
23. 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.
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)?
- (q == r) && (r == 0)
- (x > 0) && (r == x) && (y > 0)
- (q == 0) && (r == x) && (y > 0)
- (q == 0) && (y > 0)
Answer (c)
24. Consider the following snippet of a C program. Assume that swap(&x, &y) exchanges the contents of x and y.
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]);
}
Also Check: GATE Information Brochure 2024
25. The output of the program is ______
- 3
- 4
- 5
- 6
Answer (a)
GATE CSE Previous Years Question Papers with Answer Keys
Examinees can download GATE CSE's previous years' question papers from the official webpage. They must practice GATE previous years question papers for good marks in the examination. Students can practice the previous year's CSE question papers for the GATE exam tabulated below.
GATE CSE Previous Year Question Paper |
Download Link |
GATE CSE Answer Keys |
---|---|---|
2023 |
||
2022 |
||
2021 |
Forenoon: Download Now Afternoon: Download Now |
|
2020 |
||
2019 |
||
2018 |
Also Check: What is a Good GATE Score 2024?
POST YOUR COMMENT