1 CP MCQ's With Solutions 2022

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

University of Mumbai

Program: _First Year (All Branches) Engineering - SEM-II


Curriculum Scheme: Rev 2019
C-Programming
Question Bank – MCQ’s With
Solutions

============================================================================
==============================================================================
Choose the correct option for following questions. All the Questions are
Q1.
compulsory and carry equal marks
1. Which storage class is called as default storage class ?
Option A: auto : The auto storage class is the default storage class for all local variables.
Option B: register
Option C: static
Option D: extern

2. What inbuilt function should be used to return a value rounded up to the next higher
integer ?
Option A: floor
Option B: malloc
Option C: puts
Option D: ceil : This function returns nearest integer value which is greater than or
equal to the argument passed to this function.

3. In the following initialization what is value of A[5] ?


int A[10] = {9, 8, 7, 6, 5, 4, 3,2, 1, 0};
Option A: 5
Option B: 4 A[5] means 6th array element because array starts with index 0
Option C: 3
Option D: 2

4. What is the output for the following code ?


int main()
{
int a=5,i;
i!=a >10;
printf(“i=%d”,i);
return 0;
}

1) a>10 5>10 (0-false)


2) i!=0 it makes i=1

Option A: i=0
Option B: i=10
Option C: i=110
Option D: i=1

By Prof Yogesh
5. How many times will the following while-loop repeat, i.e., how many x are printed?
int main()
{
int i = 5;
while(i> 0)
{
printf(“x”);
i--;
}
return 0;
}
Option A: 2

By Prof Yogesh
Option B: 3
Option C: 4
Option D: 5 XXXXX (x=5,4,3,2,1,0(loop will stop))

6. Which among the following is an exit controlled loop ?


Option A: for
Option B: while
Option C: do… while : At least loop will run once
Option D: if…else

7 What is another name for 1-D arrays ?


Option A: Linear arrays : linear arrays are the 1- dimensional arrays wherein only one
row is present and the items are inserted
Option B: Lists
Option C: Horizontal array
Option D: Vertical array

8 Which of the following operators takes only integer operands?


Option A: +
Option B: *
Option C: /
Option D: % : It only works on integer operands

9 What is value of a in following expression?


int a = 10 + 4.867;
Option A: a=10
Option B: a=14.867
Option C: a=14
Option D: a=4

10 C programs are converted into machine language with the help of -------- --.
Option A: an editor
Option B: an Assembler
Option C: A compiler : A compiler is a program that convert a source program written in
high-level programming language such as C, Java in to machine language.
Option D: an operating system

11 What is the output of the program.?


Int main()
{
float a = 45;
printf(“%f”, a);
return 0;
}
Option A: 45
Option B: 45.0
Option C: 45.000000 (float has precision of 6)
Option D: 0.000000

12 Which among the following is a Conditional Operator in C ?


By Prof Yogesh
Option A: ?: - Ternary operator
Option B: :?
Option C: <=
Option D: >=

By Prof Yogesh
13 What is the output of the C statement.?
int main()
{
int a=0;
a = 5<2 ? 4 : 3;
//5<2 is false (0) hence false part of ?: will run hence 3 assigned to a
printf("%d",a);
return 0;
}
Option A: 4
Option B: 3
Option C: 5
Option D: 2

14 Recursion is a process in which a function calls .


Option A: itself
Option B: another function
Option C: main() function
Option D: sub program

15 What is the format specifier used to print a character in C.?


Option A: %s
Option B: %c
Option C: %C
Option D: %w

16 Which of the following is not a relational operator?


Option A: >=
Option B: >> : Bitwise Right shift operator >> is used to shift the binary sequence to right
side by specified position
Option C: ==
Option D: !=

17 Which one of the following is a valid C expression?


Option A: int my_number=1000;
Option B: int my-number=1000;
Option C: int my@number=1000;
Option D: int @mynumber=1000;

18 What will be the output of the following C code?


#include <stdio.h>
int main()
{
int a = 1, b = 1, c;
c = a++ + b;
printf("a=%d, b=%d", a, b);
}

By Prof Yogesh
/* Operators : 3)=,2)++(postfix),1)+

1) a+b is 2
2)a++ means a=a+1=1+1=2
3)c=2

a=1,b=1(unchanged),c=2*/
Option A: a=1, b=1
Option B: a=2, b=1
Option C: a=2, b=2
Option D: a=1, b=2

19 What will be the output of the following C code?

By Prof Yogesh
#include <stdio.h>
void main()
{
int x = 5;
if (x == 5)
printf("hi\n");
else
printf("how are u\n");
printf("hello\n");
}

int main()
{
int x=5;
//clrscr();

if (x==5)
printf("hi\n");
else
printf("how are u\n");

printf("hello\n");

//getch();
return 0;
}
Option A: hi
Option B: hi
hello
Option C: how are you
hello
Option D: how are you

20 What will be the output of the following C code? (Assuming that we have entered
the value 1 in the standard input).
#include <stdio.h>
void main()
{
int ch;
printf("enter a value between 1 to 2:");
scanf("%d", &ch);
switch (ch)
{
case 1:
printf("1\n");
break;
printf("hi");
default:
printf("2\n");
}
}
Option A: 1

By Prof Yogesh
Option B: 1
hi
Option C: hi
Option D: 2

21 What will be the output of the following C code?

#include <stdio.h>
int main()
{
int i = 0;
while (i = 0)
printf("True\n");
printf("False\n");
}

int main()
{
int i=0;
//clrscr();

while(i=0)
printf("True\n");

printf("False\n");

//getch();
return 0;
}

Option A: True
Option B: False
Option C: True
False
Option D: True (Infinite Times)

By Prof Yogesh
22 What will be the output of the following C code?

#include <stdio.h>
int main()
{
int x= 0;
if (x= =1)
if (x= =0)
printf("inside if\n");
else
printf("inside else if\n");
else
printf("inside else\n");
}
Option A: inside if
inside else
Option B: inside else if
Option C: inside if
Option D: inside else

23 The value obtained in the function is given back to the main program by using
which keyword?
Option A: new
Option B: return
Option C: volatile
Option D: static

24 What will be the output of the following C code?


#include <stdio.h>
void main()
{
m();
m();
}
void m()
{
static int x = 5;
x++;
printf("%d", x);
}

The static storage class instructs the compiler to keep a local variable in
existence during the life-time of the program instead of creating and
destroying it each time it comes into and goes out of scope. Therefore,
making local variables static allows them to maintain their values between
function calls
Option A: 55
Option B: 56
Option C: 66
Option D: 67

By Prof Yogesh
25 An array Index starts with.?
Option A: 0
Option B: 1
Option C: -1
Option D: 2

26 What will be the output of the following C code?


#include <stdio.h>
void main()
{

By Prof Yogesh
char string[]={'E','X','A','M','\0'};
printf("%s",string);
}
Option A: E
Option B: EXAM0
Option C: EXAM\0
Option D: EXAM

27 Which one of the following is NOT an identifier?


Option A: _cprogram

Option B: c_program

Option C: 20cprogram

Option D: cprogram20

28 What will be the output of the following program?


int main()
{
int i=9;
while(i++<10)
printf("%d\n",i);
return 0;
}

/* Operators : 2)++(postfix), 1)<


1) i<10 9<10- true hence 10 printed
2) i++ means i=i+1=9+1=10

while(10<9) -- false */
Option A: 9
Option B: 10
Option C: 1
Option D: 11

29 What will be the output of the following program?


int main()
{
int a,b,c,d,e,f,g,h,k;
a=8, b=4, c=2, d=1, e=5, f=20;
printf("%d\n",a+b-(c+d)*3%e+f/9);
return 0;
}

Option A: 10
Option B: 9
Option C: 8
Option D: 20

By Prof Yogesh
30 If a is a variable initialized to 1, how many times will the following loop be executed?
while((a>0)&&(a<25))
{
loopbody
a++;
}

#include<stdio.h>
//#include<conio.h>

int main()
{
int a=1;
//clrscr();

while((a>0)&&(a<25))
{
//loop body
a++;
}

printf("Value of a after while loop completes is %d",a);

//getch();
return 0;
}
Option A: 25
Option B: 24
Option C: 20
Option D: 26

31 In an array a[2] [2] = {10,20,30,40,50,60}, then a[0] [1] is which element?


Option A: 10

By Prof Yogesh
Option B: 20
Option C: 30
Option D: 40

32 What will be the output of the following program?


int main()
{
int a = 500, b = 100, c;
if(!a >= 400)
b = 300;
else
b=b+++b*a/b;
c = 10;
c=b<<1;
c=c>>b+1;
printf("b = %d c = %d\n", b, c);
return 0;
}

#include<stdio.h>

int main()
{
int a=500,b=100,c;

if(!a>=400)
b = 300;
else
b=b+++b*a/b;

c=10;
c=b<<1;
c=c>>b+1;

printf("b=%d c=%d\n", b, c);

return 0;
}
B=600, c=3
Option B: B=600, c=2
Option C: B=600, c=1
Option D: B=600, c=0

33 Which bitwise operator is used for turning off a particular bit in a number?
Option A: |
Option B: ^
Option C: &
Option D: ~

By Prof Yogesh
34 What will be the output of the following
program?int i;
int
goodday();
int main()
{
while(i)
{
main();
goodday()
;i++;
}
printf("Exam\n
");return 0;
}
int goodday()
{
printf("Goodday");
}

#include<stdio.h>
//#include<conio.h>

int i; //global variable hence its default value is 0


int goodday();

int main()
{
while(i) //while(0) means false hence while loop will never run
{
main();
goodday();
i++;
}
printf("Exam\n");
//getch();
return 0;
} //end of main()

int goodday()
{
printf("Goodday");
}
Option A: Goodday
Option B: Exam Goodday
By Prof Yogesh
Option C: Exam
Option D: Goodday Exam

By Prof Yogesh
By Prof Yogesh
By Prof Yogesh

You might also like