c programming gate questions
gate cse c programming questions

C Programming GATE Questions – SET 1

C Programming GATE Questions for Practice

C Programming is one the scoring subject for GATE CSE exam. Today in this tutorial we have explained some C programing gate questions for Practice  for beginners. Some of these questions are  not asked in GATE Exam but they are very similar to C Programming Gate Questions for practice.

These questions are also important for UGC NET Exam. If you are preparing for GATE  CSE Exam or UGC NET (CS) exam then you are suggested to attempt these questions and practice.

C Programming GATE Questions 

Q1. The expression that may be used to get a the remainder if we divide 3.14 via way of means of 2.1 ?

(a) the remainder = 3.14 % 2.1;

(b) the remainder = modf(3.14, 2.1);

(c) the remainder = fmod(3.14, 2.1);

(d) None.

Solution: Option (c)

Explanation:

fmod(x,y) – Calculates x modulo y, the the remainder of x/y.

This behave just like the modulus operator.

But fmod() plays floating factor divisions.

Q2. What are the sorts of linkages?

(a) Internal and External (b) External, Internal and None

(c) External and None (d) Internal

Solution: Option (b)

Explanation:

External Linkage-  way worldwide, non-static variables and capabilities.

Internal Linkage- is the specification of  static sorts  variables and capabilities having the  record scope.

None Linkage-  way Local variables.

Q3.Which of the subsequent special symbol is allowed in a variable name?

(a) * (asterisk)

(b) | (pipeline)

(c) – (hyphen)

(d) _ (underscore)

Solution: Option (d)

Explanation:

Variable names in C are made from letters (higher and decrease case) and digits. The underscore character (“_”) is likewise permitted. Names should now no longer start with a digit.

Q4. Is there any distinction among following declarations?

1: extern int fun();

2: int fun();

(a) Both are identical

(b) No distinction, besides extern int fun(); might be in some other record

(c) int fun(); is overrided with extern int fun();

(d) None of these

Solution: Option (b)

Explanation:

extern int fun(); statement in C is to signify the life of a global function  and it’s far described externally to the cutting-edge module or in some other record.

int fun(); statement in C is to signify the life of a function  with inside the cutting-edge module or withinside the identical record.

 

Q5.What  will be the output of the following program? [ Gate 2022]

#include <stdio.h>
int main(int argc, char *argv[ ]) {

int x = 1, z[2] = {10, 11};

int *p = NULL;

p = &x;

*p = 10;

p = &z[1];

*(&z[0] + 1) += 3;

printf (“%d, %d, %d\n”, x, z[0], z[1]);

return 0;

}

a. 1,10,11

b.1,10,14

c. 10,14,11

d.10,10,14

Answer – d

Explanation :

As per the code given in above program

x=1, z[0]=10 and z[1]=11

int *p= NULL; p=&x;

*p=10;

In this code segment we are modifying the value of the variable ‘x’ and it’s value gets modified as x=10.

Now after this the following statement

*(&z[0]+1)+=3;

represents that

*( address of z[0]+1 ) += 3

=>*( address of z[1] ) += 3

=>z[1] += 3 ==> z[1] = z[1] + 3

=>z[1]=14

So it is clear that the value of z[0] is not modified. Hence option D is correct.

Q6. How might you round off a cost from 1.66 to 2.0?

(a) ceil(1.sixty six) (b) floor(1.sixty six)

(c) roundup(1.sixty six) (d) roundto(1.sixty six)

Solution: Option (a)

Explanation:

/* Example for ceil() and floor() capabilities: */

#include #include

int main()

{

printf(“n Result : %f” , ceil(1.44) );

printf(“n Result : %f” , ceil(1.sixty six) ); printf(“n Result : %f” , floor(1.44) ); printf(“n Result : %f” , floor(1.sixty six) ); go back 0;

}

// Output:

// Result: 2.000000

// Result : 2.000000

// Result : 1.000000

// Result : 1.000000

Q7. By default a actual wide variety is dealt with as a:

(a) flot  (b) double

(c) long double (d) far double

Solution: Option (b)

Explanation:

In computing, ‘real number’ frequently refers to non-complicated floating-factor numbers. It consists of each rational numbers, consisting of forty two and three/four, and irrational numbers consisting of pi = 3.14159265…..

It is critical to notice that if the correctness of a floating factor wide variety isn’t always sufficient, in that case  we will use the double to outline the wide variety rather double.

To amplify the precision in addition we will use lengthy double which occupies 10 bytes of reminiscence area.

Q8. Which of the subsequent isn’t always user described statistics type?

1: struct book

{

char name[10]; double price;

int pages;

};

2: long  int l = 2.35;

3: enum day ;

(a) 1 (b) 2

(c) 3 (d) Both 1 and a pair of

Solution: Option (b)

Explanation:

C Data Types class are

Primary Data Types

(a) int

(b) char

(c) double

(d) double

(e) void

Secondary Data Types (or) User-described data types

(a) Array

(b) Pointer

(c) Structure

(d) Union

(e) Enum

This is apparent that long int l = 2.35 isn’t always User-described data  type. So long  int l = 2.35 is the right  answer.

Note – Students can study the Concepts of array hereArray in C

Q9. Is the subsequent assertion a statement or definition? extern int i;

(a) Declaration (b) Definition

(c) Function (d) Error

Solution: Option (a)

Explanation:

Declaring is the manner a programmer tells the compiler to count on a specific type, be it a variable, class/ struct/ union type, a function type (prototype) or a specific item example. (ie. extern int i).

Declaration by no means reserves any area for the variable or example withinside the software’s reminiscence; it absolutely a “hint” to the compiler that a use of the variable or example is predicted with inside the software. This hinting is technically called “ahead reference”.

Q10. Identify which of the subsequent are declarations:

1: extern int x;

2:  double square ( double x )  3:  double pow(double, double);

(a) 1 (b) 2

(c) 1 and three (d) 3

Solution: Option (c)

Explanation:

extern int x – This is statement for extern variable.

double pow(double, double) – This statement is for a function prototype.

So choice 1 and three constitute to declarations and a pair of constitute definition.

Q11.  What Value this program will print after execution [ GATE 2019]

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

}

Answer: 6

Explanation:

Since *ip=arr+4  it represent that ip is a pointer which indicate to 5th element of array because arr itself represent to first element of array which is at index 0.

Now

ip[1]= *( ip+ 1) so it will increment the pointer to next element hence 6 will be the output

Q12. In the subsequent software in which is the variable a getting described and in which it’s far getting declared?

#include int main()

{

extern int a; printf(“%dn”, a); go back 0;

}

int a=20;

(a) extern int a is statement, int a = 20 is the definition

(b) int a = 20 is statement, extern int a is the definition

(c) int a = 20 is definition, a isn’t always described

(d) a is declared, a isn’t always described

Solution: Option (a)

Explanation:

 During statement we inform the data type of the Variable.

 During definition the cost is initialized.

Q13. When we point out the prototype of a function?

(a) Defining (b) Declaring

(c) Prototyping (d) Calling

Solution: Option (b)

Explanation:

A function prototype in C or C++ is a statement of a function that omits the function frame however does specify the function’s name, argument sorts and go back type.

Where as a function definition inform approximately what a function does, a function prototype may be idea of as specifying an interface for it.

Q14. What is (void*)0?

(a) Representation of NULL pointer (b) Representation of void pointer

(c) Error (d) None of above

Solution: Option (a)

Q15. Can you integrate the subsequent statements into one? char *p;

p = (char*) malloc(100);

(a) char p = *malloc(100); (b) char *p = (char) malloc(100);

(c) char *p = (char*)malloc(100); (d) char *p = (char *)(malloc*)(100);

Solution : Option C is correct

Q16. What will be the output of this program. [ GATE 2018]

#include< stdio.h >
struct Or

{
char x,y,z;
};

int main(){

struct Or p = {‘1’, ‘0’, ‘a’+2};

struct Or *q = &p;

printf (“%c, %c”, *((char*)q+1), *((char*)q+2));

return 0;

}

The output of this program is:

(a) 0, c
(b) 0, a+2
(c) ‘0’,’a+2′
(d) ‘0’,’c’

Answer – a

Explanation :

‘a’ + 2 will be ‘c’, so Or p = {‘1’, ‘0’, ‘c’} and output will be 0,

Q17.  NULL macro is defined in which header file ?

(a) stdio.h

(b) stddef.h

(c) stdio.h and stddef.h

(d) math.h

Solution: Option (c)

Explanation:

The macro “NULL” is defined in locale.h, stddef.h, stdio.h, stdlib.h, string.h, time.h, and wchar.h.

Q18. Byte Occupy bye the near, far and huge pointers (DOS)?

(a) near=2 far=4 huge=4

(b) near=4 far=8 huge=8

(c) near=2 far=4 huge=8

(d) near=4 far=4 huge=8

Solution: Option (a)

Explanation:

near=2, far=4 and huge=4 pointers exist only under DOS. Under windows and Linux every pointers is 4 bytes long.

Q19. If a variable is a pointer to a structure, then which of the following operator is used to access data members of the structure through the pointer variable?

(a) .

(b) &

(c) *

(d) &

Solution: Option (d)

Q20.What would be the equivalent pointer expression for referring the array element a[i][j][k][l]?

(a) ((((a+i)+j)+k)+l)

(b) *(*(*(*(a+i)+j)+k)+l)

(c) (((a+i)+j)+k+l)

(d) ((a+i)+j+k+l)

Solution: Option (b)

Q21. A pointer is:

(a) A keyword used to create variables
(b) A variable that stores address of an instruction
(c) A variable that stores address of other variable
(d) All of the above

Solution: Option (c)

Q22.  Consider the given program. [ GATE 2016]

#include < stdio.h >
void mstr(int *ptra, int *ptrb) {
int *temp;
temp = ptrb;
ptrb = ptra;
ptra = temp;
}
int main() {
int a=2016, b=0, c=4, d=42;
mstr(&a, &b);
if (a < c)
mstr(&c, &a);
mstr(&a, &d);
printf(“%d\n”, a);
}
The Program will Print  _____________ ?

Answer : 2016

Explanation:

If we see tha function mstr() then we found that here only address are swapped not the value . Values will remain same in the main function. Pointer swapping is local to mstr function here in this code.

So there will be no change in the value of variable a , b , c and d

 

Q23. The operator used to get value at address stored in a pointer variable is:

(a) *

(b) &

(c) &&

(d) ||

Solution: Option (a)

Q24.. What is the output of the program given below?

#include<stdio.h>
int main()
{
enum status { pass, fail, atkt}; enum status stud1, stud2, stud3; stud1 = pass;
stud2 = atkt; stud3 = fail;
printf(“%d, %d, %d\n”, stud1, stud2, stud3); return 0;
}

(a) 0, 1, 2

(b) 1, 2, 3

(c) 0, 2, 1

(d) 1, 3, 2

Solution: Option (c)

Explanation:

enum takes the format like {0,1,2..) so pass=0, fail=1, atkt=2 stud1 = pass

(value is 0)

stud2 = atkt (value is 2) stud3 = fail (value is 1)

Hence it prints 0, 2, 1.

Q25. Consider the program [GATE 2016]

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?

(a) f(s,*s)

(b) i= f(i,s)

(c) f(i,*s)

(d) f(i,p*)

Answer : D

Explanation:  Since i is a integer and *p is value of a pointer to short.

1) Option 1 is  not correct because we are passing “*S” as second argument verify that S is not a pointer variable .So it will give error

2) Second option is we are trying to store the value of f(i,s) into i but look at the function definition outside main it has no return type. It is simply void so that assignment is wrong. So error
3) Option 3 is wrong because of the same reason why option 1 is wrong
4) So option d is correct.

Also Read – Learn C Programming 

Conclusion and Summary

We have discussed C Programming Questions for GATE exam Practice in This tutorial. I hope that these questions will be helpful for you.

Dont Stop Learning !

Leave a Reply

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