Tuesday, May 21, 2013

C MCQ Test – 1

Que.1. Explain feature of stack.
A.    stack cannot reuse its memory
B.    All elements are of different data types
C.    All operations are at one end
D.    Any element can be accessed from it directly

Right Answer: C

Que.2. The compiler in C ignores all text from a _________ until then end of a line.
A.    /
B.    */
C.    **
D.    //

Right Answer: D

Que.3. What are the total number of keywords in C?
A.    30
B.    33
C.    32
D.    35

Right Answer: C

Que.4. What is the main difference between calloc() and malloc()?
A.    calloc() takes a single argument while malloc() needs two arguments
B.    malloc() takes a single argument while calloc()needs two arguments
C.    malloc() initializes the allocated memory to ZERO
D.    calloc() initializes the allocated memory to NULL

Right Answer: B

Que.5. rand() function returns a ___________ value
A.    float
B.    any type
C.    integer
D.    both a and c above

Right Answer: C

Que.6. Which of the following below is/are valid C keywords?
A.    integer
B.    int
C.    null
D.    both a and c above

Right Answer: B

Que.7. From which of the following libraries below, calloc() belongs to?
A.    stdlib.h
B.    malloc.h
C.    calloc.h
D.    both a and b above

Right Answer: D

Que.8. What is the purpose of getc() for?
A.    read a character from STDIN
B.    read a character from a file
C.    both a and b above
D.    read a character from an input of user

Right Answer: B

Que.9. What will be the output of the following program?
float x = 3.3;
int i;
i = (int) x;
print i;
A.    3
B.    3.3
C.    3.0
D.    3.00

Right Answer: A

Que.10. Exit() is same as return?
A.    Yes
B.    No

Right Answer: B

Que.11. With every use of a memory allocation function, what function should be used
To release allocated memory which is no longer needed?
A.    unallocated()
B.    dropmem()
C.    dealloc()
D.    release()
E.    free()

Right Answer: E

Que.12. What would be the output of the following?
main()
{
int val1=1234;
int val2=01234;
printf(“%d %d”, val1, val2);
}
A.    1234 1234;
B.    1234 01234;
C.    1234 668
D.    1234 688

Right Answer: C

Que.13¬ ¬¬__________ will immediately jump to the end of the current block of code
A.    continue
B.    Exit
C.    Goto
D.    break

Right Answer: E

Que.14. int testarray[3][2][2] = {
1,2,3,4,5,6,7,8,9,10,11,12}; What value does testarray[2][1][0] in the sample code
Above contain?
A.    3
B.    5
C.    7
D.    9
E.    11

Right Answer: E

Que.15. int I,j;
int ctr = 0;
int myArray[2][3];
for (i=0;i<3;i++)
for (j=0;j<2;j++)
{
myArray[j][i]=ctr;
++ctr;
}
What is the value of myArray[1][2]; in the sample code above?
A.    1
B.    2
C.    3
D.    4
E.    5

Right Answer: E

Que.16. int a=10,b;
v=a++ + ++A;
printf(“%d, %d, %d, %d”, b,a++,a,++a);
what will be the output when following code is executed
A.    12,10,11,13
B.    22,10,11,13
C.    22,11,11,11
D.    12,11,11,11
E.    22,13,13,13

Right Answer: E

Que.17. What would be the output of the following?
main(){
char *str=”eMississippiz”;
printf(“%s”,str);
}
A.    eMississippiz
B.    eMissi ssippiz
C.    Mississippi
D.    Missi

Right Answer: A

Que.18. In C, what is the difference between a declaration and definition of a variable?
A.    Both can occur multiple times, but a declaration must occur first.
B.    Both can occur multiple times, but a definition must occur first.
C.    A definition occurs once, but declaration may occur many times.
D.    A declaration occurs once, but definition may occur many times.

Right Answer: C

Que.19. Which one of the following functions is the correct choice for moving blocks of
binary data that are of arbitrary size and position in memory?
A.    memcpy()
B.    memset()
C.    strcpy()
D.    strcpy()
E.    memove()

Right Answer: E

Que.20. Can getch() be used to echo the input?
A.    Yes
B.    No

Right Answer: B

C++ MCQ Test – 1

Que.1. Which of the following cannot be inherited from the base class?

A.    Constructor
B.     Friend
C.    Both a and b cannot be inherited
D.    Both a and b can be inherited

Right Answer: C

Que.2. class derived: public base1, public base2{} is an example of

A.    Polymorphic inheritance
B.     Multilevel inheritance
C.    Hierarchical inheritance
D.    Multiple inheritance

Right Answer: D

Que.3. Which of the following is a valid destructor of the class name “Country”

A.    int ~Country()
B.     void Country()
C.    int ~Country(Contry obj)
D.    void ~Country()

Right Answer: D

Que.4. class Example {

Public: int a,b,c;
Example () {a=b=c=1 ;} // Constructor 1
Example (int a) {a=a; b=c=1;} // Constructor 2
Example (int a, int b) {a=a; b=b; c=c;} // Constructor 3
Example (int a, int b, int c){ a=a; b=b; c=c;} // Constructor 4 }
In the above example of constructor overloading, the following statement will call which
constructor
Example obj = new Example (1,2,3.3)

A.    Constructor 2
B.     Constructor 4
C.    Constructor 1
D.    Type mismatch error

Right Answer: B

Que.5. If a class x needs to be derived from a class y, which of the following ways is
Correct to do so?

A.    Class x: public y
B.     Class y : public x
C.    Class x derives public y
D.    Class y derives public x

Right Answer: A

Que.6. A class cannot inherit members from more than one class

A.    True
B.     False

Right Answer: B

Que.7.  Which of the following is not true about preprocessor directives

A.    They begin with a hash symbol
B.     They are processed by a preprocessor
C.    They from an integral part of the code
D.    They have to end with a semi colon

Right Answer: D

Que.8. The output of this program is

int
main () {
cont<<”Hello World”
return 0;
}

A.    Hello World
B.     Syntax error
C.    0
D.    Hello World!

Right Answer: B

Que.9. Can inline functions be used to improve performance?

A.    Yes
B.     No
C.    Yes, depends on the situation
D.    Both a and b

Right Answer: D

Que.10. If a member needs to have unique value for all the objects of that same class,
declare the member as

A.    Global variable outside class
B.     Local variable inside constructor
C.    Static variable inside class
D.    Dynamic variable inside class

Right Answer: B

Que.11. int a = 10;

Void main()
{
int a = 20;
count <<a<<::a;
}
The output of this program is

A.    Syntax error
B.     10 20
C.    20 10
D.    20 20

Right Answer: C

Que.12. Write the output of the following;

char *mychar; // points to memory location 1000
short *mychart; // points to memory location 2000
long *mylong// points to memory location 3000
mychar++;
++myshort;
mylong++;
count<<mychar<<myshort<<mylong;

A.    1001 2001 3001
B.     1001 2002 3004
C.    1001 2001 3002
D.    1001 2002 3004

Right Answer: D

Que.13. Which one of the following is not a fundamental data type in C++

A.    float
B.     string
C.    Int
D.    Wchar_t

Right Answer: B

Que.14. What is the output of the following code snippet assuming user enters the side
as 4?
class square
{
Public:
double side1;
double area() {
double (side1*side1);
}
};
int main(){
double area1=0;
squre c1,c2;
count<<”Enter the length of the squre”<<endl;
cin>>c1.side;
cout<<”The area of  the square is : “<<c1.area1()<<endl;
return (0);
}

A.    16
B.     Will result in an error
C.    8
D.    12

Right Answer: B

Que.15. When class B is inherited from class A, what is the order in which the
constructor of those classes are called

A.    Class A first Class B next
B.     Class B first Class A next
C.    Class B’s only as it is the child class
D.    Class A’s only as it is the parent class

Right Answer: A

Que.16. Which one of the following is not a valid reserved keyword in C++

A.    Explicit
B.     Public
C.    Implicit
D.    Private

Right Answer: C

Que.17. Value of a in a = (b = 5, b + 5); is

A.    Junk value
B.     Syntax error
C.    5
D.    10

Right Answer: D

Que.18. A null pointer is nothing but a void pointer pointing to nowhere.

A.    True
B.     False

Right Answer: B

Que.19. Which of the following members do get inherited but become private members
in child class

A.    Public
B.     Private
C.    Protected
D.    All of the above

Right Answer: C

Que.20. What is a virtual member?

A.    A member of a friend class that can be redefined in its derived classes
B.     A member of a virtual class that cannot be redefined in its derived classes
C.    A member of a static class that can be redefined in its derived classes
D.    A member of a class that can be redefined in its classes

Right Answer: D