Monday 26 December 2016

C++

Storage Classes in C++



A storage class defines the scope (visibility) and life-time of variables and/or functions within a C++ Program. These specifiers precede the type that they modify. There are following storage classes, which can be used in a C++ Program (MESRA trick to remember)
·        auto
·        register
·        static
·        extern
·        mutable

QuestionID  :  1000         Subject Name  CPP
Q1. Which of the following keywords do you think can be used when declaring static members in a class?
i)Public
ii)Private
iii)Protected
     1.  Only i
     2.  i and ii
     3.  i, ii and iii
     4.  i and iii
     Correct Answer : 3
      1
QuestionID  :  1032         Subject Name  CPP
Q2. Identify the true statements about a this pointer.
i)It is initialized automatically to the memory address of the object in which it is contained.
ii)It is a pointer to an object`s member functions.
iii)It can`t be used explicitly in a program.
iv)It is of the same type as the object in which it is contained.
     1.  i and iv.
     2.  ii, iii and iv.
     3.  i, ii, iii and iv.
     4.  i and iii
     Correct Answer : 1
     
QuestionID  :  1101         Subject Name  CPP
Q3. int diff(int x)
{int s;
s -= diff(x-1);
return(s);}
void main()
{int res = diff(5);
cout << res;}
Determine the output of the code written above:
     1.  -15
     2.  0
     3.  Compilation error.
     4.  Stack overflow.
     Correct Answer : 4
     
QuestionID  :  1107         Subject Name  CPP
Q4. Identify the true statements about the use of pointers in C++.
i)A pointer is a variable that can contain the memory address of another variable as its value.
ii)Though not necessary, pointers make the use of dynamic memory allocation more efficient.
iii)You can use casting to cause a pointer of one type to reference the memory address of a variable of another type.
iv)In a cout statement, you can use a pointer to display a memory address.
     1.  i, ii and iv.
     2.  ii, iii and iv.
     3.  i, ii, iii and iv.
     4.  i and iii
     Correct Answer : 3
     
QuestionID  :  1137         Subject Name  CPP
Q5. In the array representation of circular queue when we can say that queue is full ?
     1.  Front = Rear.
     2.  Front = Rear - 1.
     3.  Rear = Front ? 1.
     4.  Can?t say.
     Correct Answer : 1
     
QuestionID  :  1155         Subject Name  CPP
Q6. Identify the true statements about a link/next pointer.?
i)Its value should be changed only if the linked list`s head changes?
ii)It is a self-referential class data member?
iii)It is used to reference a node in a linked list?
iv)If it belongs to the last node in the list, it should have a NULL value
     1.  i,ii and iv.
     2.  ii, iii and iv
     3.  i, ii and iii
     4.  i and iii
     Correct Answer : 2
     
QuestionID  :  8234         Subject Name  CPP
Q7. An instance is
     1.  a non-static Data Member
     2.  neccessary to establish inheritance
     3.  not an Object related issue
     4.  None of the above
     Correct Answer : 1
     
QuestionID  :  8256         Subject Name  CPP
Q8. An Object is
     1.  a class declration for an instance
     2.  composed of data, and functions that operate on the data
     3.  an physical non-living entity
     4.  an abstract concept
     Correct Answer : 2
     
QuestionID  :  8375         Subject Name  CPP
Q9. What will be the output?
#include < iostream.h >
using namespace std;
main()
{
cout << "best of luck!";
}
     1.  best of luck
     2.  best of luck!
     3.  compilation error
     4.  none of the above
     Correct Answer : 3
     
QuestionID  :  8378         Subject Name  CPP
Q10. what will be the c++ output of the following code...
int x1=1000.2500;
main()
{
int x1=1110;
x1=1100.35;
cout << (::x1)+x1;
}
     1.  2101
     2.  2111
     3.  2100
     4.  compilation error
     Correct Answer : 3
     
QuestionID  :  8397         Subject Name  CPP
Q11. What will be the C++ output of the following code
(Number entered=100)
#include < iostream.h >
main()
{
int i1;
cout << endl << "enter the four digit;
//enter number 100
cin >> i1;
try
{
if(i1 < 1000)
throw (1);
else
{
if(i1%2)
throw (2);
else
throw (3);
}
}catch(int i1)
{
if(i1==2)
cout << "even number";
else
cout << "odd number";
}
return (0);
}
     1.  runtime error
     2.  compilation error
     3.  even number
     4.  odd number
     Correct Answer : 4
     
QuestionID  :  8453         Subject Name  CPP
Q12. C is derived from classes A and B means the type of inheritance is-
     1.  single
     2.  hierarchial
     3.  multilevel
     4.  multiple
     Correct Answer : 4
     
QuestionID  :  8551         Subject Name  CPP
Q13. In the c++ statement

int &sqrt=s1;
     1.  & is the bitwise AND operator
     2.  sqrt is a reference variable of data type of s1
     3.  sqrt is a reference variable of data type of int
     4.  None of the above
     Correct Answer : 3
     
QuestionID  :  8655         Subject Name  CPP
Q14. all variables used in the test expression of the while statement must be initialised is
     1.  always true
     2.  entirely baseless
     3.  not mandatory
     4.  both 2 & 3
     Correct Answer : 1
     
QuestionID  :  8770         Subject Name  CPP
Q15. what will be the c++ output of the following code?
int x1=1000;
main()
{
int x=1100;
cout << ((::x1)+x1);
}
return (0);
}
     1.  2000
     2.  2100
     3.  2110
     4.  compilationerror
     Correct Answer : 3
     
QuestionID  :  8772         Subject Name  CPP
Q16. /* This is // a comment */
C++ compiler will
     1.  ignore entire line
     2.  ignore everything after //
     3.  give a compilation error
     4.  Nothing will be ignored
     Correct Answer : 1
     
QuestionID  :  8904         Subject Name  CPP
Q17.
When a derived class object is placed in a base class variable
     1.  
it acts like a base class object
     2.  
it remains to behave as a derived class object
     3.  
it gives compilation error
     4.  
none
     Correct Answer : 1
     
QuestionID  :  8912         Subject Name  CPP
Q18.
Which of the following ia not a C++ operator?
     1.  
^=
     2.  
.*
     3.  
&=
     4.  
->>
     Correct Answer : 4
     
QuestionID  :  8938         Subject Name  CPP
Q19.
What does following signify int *p = &++a
     1.  
p points to a
     2.  
p is an reference of a
     3.  
Error on compilation
     4.  
None of above
     Correct Answer : 3
     
QuestionID  :  8963         Subject Name  CPP
Q20.
Static data members cannot be private.
     Correct Answer : F
     
QuestionID  :  8978         Subject Name  CPP
Q21.
if tree has only one node than the tree may be a
     1.  
binary tree
     2.  
tertiary tree
     3.  
not a tree
     4.  
a and b
     Correct Answer : 4
     
QuestionID  :  9077         Subject Name  CPP
Q22.
C++ treats its data as
     1.  
a flowchart
     2.  
flowdiagram
     3.  
streams
     4.  
System canals
     Correct Answer : 3
     
QuestionID  :  9115         Subject Name  CPP
Q23.
In C++ identifier can begin with a $ sign.
     Correct Answer : T
     
QuestionID  :  9209         Subject Name  CPP
Q24. #include < iostream.h >
void main()
{
const int num=5;
int *p=const_cast< int* >(&num);
*p=10; ++*p;
cout << num ;
}
     1.  5
     2.  10
     3.  11
     4.  compiler error
     Correct Answer : 1
     
QuestionID  :  9226         Subject Name  CPP
Q25. Which of the following are true about virtual functions
     1.  They cannot be static members
     2.  The virtual functions must be members of same class
     3.  They are accessed using object pointers
     4.  All of above
     Correct Answer : 4
     
QuestionID  :  9256         Subject Name  CPP
Q26. OOP revolves largely around classes because
     1.  They bring together attributes and behavior of objects
     2.  They permit the data to be hidden or exposed
     3.  They help to model real world objects
     4.  All of above
     Correct Answer : 4
     
QuestionID  :  9272         Subject Name  CPP
Q27. Which of the following is true for exception handling
     1.  the catch block immediately follows try block
     2.  throw block follows the catch block
     3.  finally block follows catch block
     4.  None of the above
     Correct Answer : 1
     
QuestionID  :  11754         Subject Name  CPP
Q28. What will be the switch statement display if the id variable contains the number 2?
Use the following switch statement to answer questions 42 through 44. id is a short Integer variable.

Switch(id)
{
case 1:
cout << "Jane" << endl;
break;
case 2 :
cout << "paul" << endl;
break;
case 3 :
case 5:
cout << "Jerry" << endl;
break;
default :cout << "Sue" << endl;
}
}
     1.  Sue
     2.  Paul
     3.  Jerry
     4.  Janet
     Correct Answer : 2
     
QuestionID  :  11920         Subject Name  CPP
Q29. Inheritance occure when class adopts allthe traits of-------
     1.  a function
     2.  variable
     3.  a parent class
     4.  an object
     Correct Answer : 3
     
QuestionID  :  11938         Subject Name  CPP
Q30. to overload a postfix ++ for a number class, an appropriate function header is
     1.  this number::operator++(number &num)
     2.  number& number
::operator++()
     3.  number& number
::operator++(int)
     4.  number& number
::operator++(number &num)
     Correct Answer : 3
     
QuestionID  :  11973         Subject Name  CPP
Q31. The first node in a binary tree list is called the_________.
     1.  head pointer
     2.  binary node
     3.  root node
     4.  pointer node
     Correct Answer : 3
     
QuestionID  :  11974         Subject Name  CPP
Q32. A binary search tree can be created using a struct containing data value
and ____________
     1.  a pointer to first child node
     2.  a pointer to last child node
     3.  two pointers one for the left child and one for the right child
     4.  two data nodes
     Correct Answer : 3
     
QuestionID  :  12074         Subject Name  CPP
Q33. It is _________ to pass an argument to a function that contains an individual array element, such as numbers[3].
     1.  illegal in C++
     2.  legal in C++
     3.  not recommended by the ANSI committee
     4.  not good programming practice
     Correct Answer : 2
     
QuestionID  :  12082         Subject Name  CPP
Q34. To use a template class member function, use the -------with the instantiation .
     1.  Keyword template
     2.  Class Defination
     3.  Dot operator
     4.  scope resolution operator
     Correct Answer : 4
     
QuestionID  :  12098         Subject Name  CPP
Q35. The auto_ptr belongs to
     1.  memory header file
     2.  graphics file
     3.  iostream header file
     4.  void header file
     Correct Answer : 1
     
QuestionID  :  12109         Subject Name  CPP
Q36. A tree with a height of 3 has
     1.  six nodes
     2.  one root and three nodes with two children each
     3.  three levels
     4.  three subtrees
     Correct Answer : 3
     
QuestionID  :  12116         Subject Name  CPP
Q37. Data structure that can dynamically store elements and can grow and shrink in the size are:
     1.  Stacks
     2.  Queues
     3.  Deques
     4.  All of these
     Correct Answer : 4
     
QuestionID  :  12131         Subject Name  CPP
Q38. C++ limits the number of array dimensions to two.
     Correct Answer : F
     
QuestionID  :  12156         Subject Name  CPP
Q39. What will be the output of the following program if your integer inputs are 88, 64 and 37 ?
main()
{
int a, b,c;
cout << "Enter three integers: ";
cin >> a >> b >> c;
if (a >=b && a >=c ) cout << a endl;
if(b >=a && b >=c ) cout << b endl;)
if(c >=a && c >=b ) cout << c endl;)
}
}
     1.  37
     2.  88
     3.  64
     4.  176
     Correct Answer : 2
     
QuestionID  :  12297         Subject Name  CPP
Q40. To avoid the duplication of inherited members due to different paths of inheritance.It is better to design the common base class as
     1.  vital base function
     2.  base class with no members
     3.  virtual base class
     4.  base class with members initialized to zero
     Correct Answer : 3
     
QuestionID  :  12310         Subject Name  CPP
Q41. what is the code effect on compilation
const MAX=50
void main()
{cout << max;}
     1.  output will be 50
     2.  output will be MAX
     3.  Error
     4.  Ascii value of `M`
     Correct Answer : 3
     
QuestionID  :  12317         Subject Name  CPP
Q42. A new node cannot become the first node in the list
     Correct Answer : F
     
QuestionID  :  12336         Subject Name  CPP
Q43. __________members of a base class are never accessible to a
derived class.
     1.  public
     2.  private
     3.  protected
     4.  a,b,and c
     Correct Answer : 2
     
QuestionID  :  12340         Subject Name  CPP
Q44. Stack and Queue can be implemented as arrays or linked list.
     Correct Answer : T
     
QuestionID  :  12354         Subject Name  CPP
Q45. Most of the lines in a program contains something meaningfull; however, some of the lines contain nothing at all
     Correct Answer : T
     
QuestionID  :  12467         Subject Name  CPP
Q46. recursive algorithemare less efficent then iterative algorithem
     Correct Answer : T
     
QuestionID  :  12512         Subject Name  CPP
Q47. class copy constructor should be used when
     1.  new object is initialized to existing object of same class
     2.  class is derive class
     3.  constructor is default
     4.  new class is to be derived from existing class
     Correct Answer : 1
     
QuestionID  :  12515         Subject Name  CPP
Q48. The line containing a throw statement is known as the throw point.
     Correct Answer : T
     
QuestionID  :  12585         Subject Name  CPP
Q49. friend function can actually used to
     1.  prevent clashes between two or more classes
     2.  use object of private classes
     3.  allow a class to access an unrelated class
     4.  all of above
     Correct Answer : 3
     
QuestionID  :  12613         Subject Name  CPP
Q50. in case of class fails to redefine a virtual function
     1.  the function will be destroyed
     2.  the class will used base class version of function
     3.  the class will give compilation error
     4.  the class will not be implemented
     Correct Answer : 2