Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

MCQs

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 11

Set –I

1. Choose the correct alternatives for the following:


i) The output of the following code is
void main( )
{Recursion
int arr[6]={20,25};
clrscr( );
printf("%d %d %d", arr[2],arr[3],arr[4));
}
a) 25 0 0 b) 10 0 25
c) 0 0 0 d) none of these.
Ans: c)
Explanation : If an array is initialized with smaller number of elements at the time of
declaration, rest locations are initialized by zero.

ii) A pointer is
a) a value
b) a variable containing the address of a variable
c) a memory location
d) none of these.
Ans: b)

iii) The output of the following code is


void main()
{
int n = 5;
fun(n);
printf("%4d", n);
getch ();
}
fun(int n)
{
return ++n;
}
a) 6 b) 5
c) 4 d) none of these.
Ans: b)
Explanation : The function is invoked using call by value mechanism, so value of n will be
remain unchanged at main function.

iv) File input/output programs would require which include file ?


a) stdlib.h b) conio.h
c) dos.h d) stdio.h
Ans: d)
v) The union holds
a) one object at a time b) multiple objects
c) both (a) and (b) d) none of these.
Ans: a)

vi) What will be the value of i and m after executing the following code segment ?
int i=5, m;
m=i++;
a) 5 and 6 b) 6 and 5
c) 5 and 5 d) 6 and 6.
Ans: b)

vii) The output of the following code segment is


fact= l ;
for(i= l ;i<5;i++);
fact=fact*i;
a) 24 b) infinite loop
c) 5 d) none of these.
Ans: c)

Explanation : here, for loop is ended with a ;, the for statement becomes
for(i= l ;i<5;i++)
{;}
So, when the loop will be terminated the value of i becomes 5.

viii) The purpose of mode r+ is to


a) open for only reading
b) open for only writing
c) open for both reading and writing
d) none of these.
Ans: c)

ix) The output of the following code is

main ( )
{
int d = 0 ;
if (d=5)
printf("Right");
else
printf("Wrong");
}
a) Right b) Wrong
c) WrongRight d) None of these.
Ans: a)
Explanation: Instead of comparison at the if statement, 5 will be assigned to d and the if
statement become if(5) which is true.

x) An array is a collection of
a) different data types scattered throughout memory
b) same data type scattered throughout memory
c) different data types placed next to each other in memory
d) same data type placed next to each other in memory.
Ans: d)

Set –II

2. Choose the correct alternatives for the following:


i) Output of the following code is
#define N 2+3
main ( )
{
int a;
a=N*N;
printf(“%d”,a);
}
a) 25 b) 11
c) 0 d) none of these.

Ans: b)

Explanation : a = 2+3*2+3
= 2+6+3
= 11

ii) Output of the following code is


main ( )
{
int a[]={0,1,2,3,4}
int k, *p;
for (p=a, k=0; p+k<=a+4; p++, k++)
printf(“%d”, *(p+k));

}
a) 01234 b) 024
c) compiler error d) none of these.

Ans: b)
iii) Output of the following code is
main ( )
{
int a[2][3] = { l, 2, 3, 4, 5, 6};
printf (“%d”, *(*(a+l)+2) );
}
a) 6 b) 2
c) compiler error d) none of these.

Ans: a)

iv) Output of the following code is


#include<string.h>
main ( )
{
int k=strcmp(“abc”, “Abc”);
printf (“%d”, k);
}
a) 0 b) 65
c) -65 d) none of these.

Ans: d)
Explanation : The ASCII value difference of ‘a’ and ‘A’ is 32. So, output will be 32.

v) Output of the following code is


#include<string.h>
main ( )
{
char s[] = “hello”;
printf (“%d”, *(s+strlen(s)));
}
a) 0 b) 5
c) compiler error d) none of these.
Ans: a)
Explanation : as *(s+strlen(s)) represents ‘\0’.

vi) Output of the following code is


#include<string.h>
main ( )
{
char ch[5];
int j;
for (j=0; j<5; j++)
ch[j]=65;
ch[j]=‘\0’;
printf(“%s”, ch);
}
a) AAAA b) AAAAA
c) compiler error d) none of these.
Ans: b)

vii) A typecast is used to


a) define a new data type
b) force a variable to be of a particular type
c) rename an old type
d) none of these.
Ans: b)

viii) When applied to a variable, what does the unary “&” operator yield ?
a) the variable’s address
b) the variable’s right value
c) the variable’s binary form
d) the variable’s value.
Ans: a)

ix) What will print when the sample code is executed ?


void main ( )
{
int z, x=5, y= -10, a=4, b=2;
z=x++ - --y * b / a;
printf(“%d”, z);
}
a) 5 b) 6
c) 10 d) 11.
Ans: c)

x) Consider the following declaration :

char const *p = ‘d’;

Which of the following is not a permissible operation ?

a) *p++
b) ++p
c) (*p)++
d) all.
Ans: c)
Explanation : A constant object cannot be modified.
Set –III

3. Choose the correct alternatives for the following: 10 x 1 = 10


i) C is a …………… .language.
a) Procedural b) Object-oriented
c) Both (a) and (b) d) None of these.
Ans: a)

ii) The following code execution is


void fn(int m)
{
printf (“%d”, m) ;

fn(m+1);

}
a) finite b) infinite
c) stack overflow d) can’t say.
Ans: c)

iii) Output of the following code is


int a = 8 , b = 5;
printf("%d”, a*++b+b++) ;
a) 54 b) 55
c) 46 d) 47
Ans: a)

iv) If you pass an array as argument in a function, then it is


a) Call by value b) Call by reference
c) Call by name d) All of these.
Ans: b)

v) Which operator can have only integer operands ?


a) * b) /
c) + d) %
Ans: d)

vi) In the main function, we can pass


a) no argument b) one argument
c) two arguments d) all of these.
Ans: d)

vii) What is the output of the following code ?


#define M(x) x*x
main( )
{
int i = M( 2+6);
printf( “%d”, i);'
}
a) 64 b) 44
c) 40 d) 20.
Ans: d)

viii) To dynamically allocate a memory we use


a) malloc ( ) b) realloc ( )
c) Both (a) and (b) d) none of these.
Ans: c)

ix) Which of the user defined data types store(s) different types of data in a single location?
a) Structure b) Union
c) Both (a) and (b) d) None of these.
Ans: b)

x) The fopen( ) function returns ………….. when the file is not opened.
a) -1 b) 1
c) NULL d) None of these.
Ans: c)

Set –IV

4. Choose the correct alternatives of the following :


i) The minimum number of temporary variables needed to swap two variables is

a) 1 b) 0
c) compiler dependent d) 2.
Ans: b)

ii) Which of the following operators that doesn't associate from left ?
a) ? : b) &&
c) , d) | |
Ans: a)

iii) int i, f = l;
for ( i = l ; i<=5; i++);
f = f * i;
printf ( “%d”, f);
. results in the printing of
a) 0 b) 5
c) 120 d) 6.
Ans: d)
iv) The expression 4 + 6/3*2-2 +7%3 evaluates to
a) 3 b) 4
c) 6 d) 7.
Ans: d)

v) How long the following loop runs ?


for ( x = 0 ; x = 3 ; x++)
a) Three times b) Four times
c) Forever d) Never.
Ans: d)

vi) Data type of the controlling statement of a SWITCH statement cannot of the type
a) int b) char
c) short d) float.
Ans: d)

vii) main ( )
{
int a = 3;
printf ( “%d%d%d%d%d”, a++, ++a, ++a, a++);
}
a) 3566 b) 6653
c) 3565 d) 6666
Ans: b)

viii) Which of the following is not valid variable declaration ?


a) int aandb b) int a & b
c) int print d) int _print
Ans: b)

ix) How many times the following loop will execute ?


int x = 2345;
while(x>0){x = x/ 10;}
a) 3 b) Infinite times
c) 4 d) 5
Ans: c)

x) How many times the message Hello will be printed in the following program?
void main( )
{
int x;
for (x = -1;x<=10;x++)
{
if(x<5)
continue;
else
break;
printf(“Hello”);
}
}
a) 11 times b) 10 times
c) once d) 0 times.
Ans: d)

Set –V

5. Choose the correct alternatives of the following :


i) Find out the output of the following program segment :
main ( )
{
int a,b,c;
b=2:
a=2 * (b++) ;
c=2*(++b);
}
a) a = 4, c = 6 b) a = 3, c = 8
c) a = 3, c = 6 d) a = 4, c = 8.
Ans: d)

ii) ln the following statement


fprintf ( fpt, “ %d”, 1), the variable fpt is
a) a character variable b) a pointer to a file
c) a file variable d) arbitrarily assigned value
Ans: b)

iii) How many times will the loop be executed ?


C1 = ‘a’ ;
While (C1 > = ‘a’ && C1 < =’z’)
C1++ ;
a) 25 b) 26
c) 0 d) 1
Ans: b)

iv) What would be the correct output of the following program ?


void main ( )
{
int k, num=30;
k = (num>5? (num<=10?100:200) : 500);
printf("%d%d",num,k);
}
a) 200 30 b) 30 100
c) 30 200 d) 30 500.
Ans: c)

v) If integer needs 2 bytes storage, then maximum value of an unsigned integer


a) 216 – 1 b) 215-1
16
c) 2 d) 215
Ans: a)

vi)) Choose the correct output:


void main ( )
{
char str[20]= “Hello”;
char * const p=str ;
*p=’M’;
printf(“%s”, str);
}
a) Mello b) Hello
c) HMello d) MHello.
Ans: a)

vii) Assume that x = 50. Then what is the value of y where y = x = = x++; ?
a) 0 b) 1
c) 51 d) 50
Ans: b)

viii) Register variable has the default value


a) garbage b) 0
c) 1 d) NULL
Ans: a)

ix) The function func (n) = 1 + 2 + 3 + ……………+ n can be recursively written as


a) func (n) = func (1) + func 2) + ……………+func (n)
b) func (n) = n + func(n-1), when n >1
= 1 , when n = 1
c) func (n) = func (n – 1) + func(n-2), when n >1
=1 , when n = 1
d) func (n) = func (n – 1) + 1, when n >1
=1 , when n = 1

Ans: b)

x) If a two- dimensional array int a [ 10 ] [ 20 ] is represented as an array of pointers, then the


element a [ 4 ] [ 5 ] can be denoted as
a) *(a+4)+5 b) *a [ 4 ] + 5
c) * ( * ( a + 4 ) + 5) d) *(a [ 4 ] + 5 )
Ans: c)

You might also like