You cannot copy content of this page.

Category Archive C++

Fill up the blank in C++




Fill up the blank in C++

( SET- I )

1. hecadecimal 2. derived 3. cout
4. sensitive 5. enumerator 6. \0n
7. binary 8. identifier 9. <<
10. string literal 11. comma 12. >>
13. decimal 14. character literal 15. token
16. atomic 17. primitive 18. cin
19. insensitive 20. octal 21. const
22. ternary 23. precedence 24. union
25. sizeof operator 26. semantical 27. class
28. void 29. struct 30. type casting

 
1. The smallest individual unit in a program is known as a ……………………

2. C++ Language is case ………………….

3. An ………………… is a long sequence of letters and digits.

4. A sequence of digits beginning with zero is considered to be …………….number.

5. ………………. escape sequence represents the given number in octal form.

6. A ……………………. is a sequence of characters surrounded by double quotes.

7. Fundamental data types may be used to construct ………………… data types.

8. ………………. data types are those that are not composed of other data types.

9. ……………. is a predefined object that represents the standard output stream in C++.

10. ……………….. is used to name integer constants using enum keyword.

11. ………………..operator in C++, requires three operands.

12. A ……………………. variable must be initialized at the time of its declaration.

13. The operator ………………………. is called the insertion or put-to operator.

14. A ………………….. operator is used to group together several expressions.

15. Errors may be syntactical or …………………….

16. The ……………………. determines the order of evaluation of an expression.

17. The process of converting one data type to another type is called …………………………

18. ……………………… returns the size of a variable in bytes.

19. …………………….. data type cannot be used to declare variables in C++.

20. The data type used to share a memory location by two or more variables is ………………………
 
( SET – II )

1. for 2. innermost 3. iterative
4. subscript 5. 9 6. reference
7. float 8. prototype 9. extern
10. do..while 11. definition 12. goto
13. void 14. conditional 15. >>
16. 10 17. extern 18. <<
19. getchar() 20. initialize 21. auto
22. while() 23. outermost 24. curly brackets
25. int 26. register 27. curved brackets
28. 11 29. define 30. same
31. zero 32. different

1. If the maximum subscript value of an array is 9, then the size of the array is ………………………..

2. switch() is an example of ……………………….. construct.

3. ……………………… loop is a bottom tested loop.

4. An exception to procedural programming language is the use of …………………. statement.

5. break terminates the …………………….. loop.

6. …………………… function is used to read a character from the keyboard.

7. …………………… operator defines the size of an array.

8. The default return type of a function is …………………

9. A function …………………… is required whenever we invoke a function before defining it.

10. Structure objects may be returned by …………………..

11. The scope of …………………variable is the function scope.

12. The scope of …………………variable is file scope.

13. The …………………….. variable is stored in fast access memory location.

14. ………………….. is the stream insertion operator.

15. ………………….. is the stream extraction operator.

16. ……………………keyword is used to declare a macro.

17. Constructors are used to …………………… the data members automatically, whenever an object of a class is instantiated.

18. A function body is delimited by ……………………….

19. The array elements mus be of the ……………… data type.

20. The …………………. pointer is normally used to indicate that the pointer does not contain an active entry.
 

( SET – III )

1. <iomanip.h> 2. optional 3. continue
4. formal 5. register 6. subscript
7. extern 8. setf() 9. <fstream.h>
10. unitbuf 11. unsigned 12. break
13. actual 14. inline 15. width()
16. <iostream.h> 17. initialization 18. extensibility
19. recursive 20. auto 21. return
22. non-recursive 23. essential 24. pointer
25. member function 26. preprocessor 27. int
28. friend 29. float 30. data abstraction

1. ………………….. function of ios class is used to set format flags.

2. …………………. function determines the size of the output field.

3. …………………. flushes all streams after insertion.

4. The header file …………………….. provides manipulators to set output formats.

5. main() is an ……………………component of every C++ program.

6. A variable must be declared before its ……………………….

7. ………………….. statement repeats the loop by skipping the remaining portion.

8. ……………………statement is used to transfer a value from the invoked function to the invoking function.

9. The arguments used in function call statement are ………………… arguments.

10. The arguments used in function definition are ……………. arguments.

11. A ………………….. variable is similar to that of an auto variable with the only difference that it is stored in a fast access memory location.

12. A function call from within itself results in ………………….. call.

13. …………………… … statements are those which are executed during compile time.

14. …………………….header file contains necessary declarations for input/ output in C++.

15. [ ] operator is called …………………….operator.

16. A ……………………. variable is a variable that contains the address of some other variable.

17. ………………………. keyword is used to declare a variable that may contain only positive values.

18. When a language has the capability to produce new data types, it is said to be ………………………….

19. When a language allows only the defining operations of a type of access the low level representation of a type, that language is said to enforce ……………………..

20. In C++, the public/private distinction applies only to members of a class, so …………………….. functions can be listed in either part of the class.
 

( SET – IV )

1. struct 2. public 3. private
4. colon 5. auto 6. default
7. data encapsulation 8. destroyed 9. scope resolution
10. structure 11. data abstraction 12. definition
13. protected 14. signature 15. volatile
16. class 17. instantiated 18. scope resolution operator
19. semicolon 20. delete 21. inheritance
22. zero 23. polymorphic 24. function overloading
25. polymorphism 26. new 27. one

1. ……………………….. refers to hiding physical details and displaying only the desired information.

2. ………………………… provides data security by hiding it from the external world.

3. ……………………. contains data members and methods to operate on these members.

4. ……………………. contains data members only.

5. The member functions, if defined outside the class must use ………………………..

6. The class members by default are ……………………

7. ……………………. variables may be modified by some method which is not known to the program.

8. A class declaration ends with a ………………………

9. Memory to data members of a class is allocated when an object of a class is ……………………..

10. A ……………………. constructor can have default arguments.

11. Sharing of information which is common is achieved through ………………………

12. Friend functions can only access …………………….. data members.

13. …………………… operator is used to free memory allocated using new operator.

14. Function prototype is also called function ……………………….

15. A ………………………… class is one that contains a virtual function.

16. A unary overloaded operator via member function needs ………………… arguments.

17. A binary operator overloaded via member function needs ………………… arguments.

18. Defining two or more functions with the same name but with different set of arguments and return type is ………………………….

19. A user can inform the compiler to use the global variable rather than local variable by prefixing the variable with the ………………… operator.

20. In C++, ……………………….. allows to ignore the data representation in memory, and to think in terms of what operations can be performed on the data.
 

( SET – V )

1. throw 2. unexpected() 3. exception handling
4. virtual 5. this 6. setbase
7. seekg() 8. templates 9. catch
10. abstraction 11. structure 12. non-primitive
13. template 14. primitive 15. virtual
16. identity 17. try 18. class
19. dynamic 20. encapsulation 21. polymorphism
22. inheritance 23. binding 24. static binding

1. ………………………. are used to define generic classes in C++.

2. ………………………. is a technique to handle exceptional errors from within the program.

3. …………………….. keyword is used to define a class template.

4. …………………….. keyword is used to send a message that an error has occurred.

5. ……………………. keyword is used to receive the error information.

6. ……………………. block invokes a function that detects an exception.

7. If no appropriate handler is available, the function invoked to process the exception is ………………………..

8. A ………………………. data type is a fundamental type which is not composed of other data types.

9. A ……………………….. data type is composed of other fundamental data types.

10. A destructor function of a base class may be declared as …………………

11. In C++, ……………….. is a pointer to the invoking object of the class type.

12. An object has state, behaviour and …………………….

13. The base of a stream can be changed by the parameterized stream manipulator ……………………….

14. A ……………………….. organizes different data items so that they can be referenced as a single unit.

15. A …………………. organizes different data items so they can be referenced as a single unit, but does not contain methods that operate upon these data members.

16. The ………………………. member function of the istream class repositions the file position pointer.

17. In C++, ………………….. denotes the connection between an entity and its properties.

18. In C++, ……………………. keyword is used to force the compiler to generate only one copy of any repeated base class when the base class is inherited twice.

19. An ……………………….. separates what the user needs to know to use a piece of code from what the author had to know to write the code.

20. In …………………………, the compiler and the linker directly define the fixed address of the code to be executed on every function call.
 

( SET – VI )

1. destructor 2. getline() 3. iostream.h
4. derived 5. abstraction 6. protected
7. private 8. arrow 9. ios::noreplace
10. abstract 11. constructor 12. static
13. fstream.h 14. enumerator 15. ios::nocreate
16. new 17. const 18. preprocessor directives
19. subscript 20. aggregation 21. base
22. atoi() 23. cout 24. encapsulation
25. dot 26. static binding 25. cin
28. inline

1. The …………………… header file contains information important for user controlled file processing operations.

2. …………………….. denotes a whole/part hierarchy, with the ability to navigate from the whole to its parts.

3. A …………………… function is the first member function which is invoked when an object of the class is being created.

4. Using an array name without a …………………… yields a pointer to the first element of the array.

5. The …………………… member function of istream class of C++ reads over a designated number of characters and termiates upon encountering a designated character.

6. In C++, to show that a member function does not change its invoking object, …………………… keyword is placed after the closing parenthesis in the function declaration and definition.

7. ………………….. classes have no access to private members of base class.

8. In C++, …………………… makes prototyping more practical.

9. The ……………….. function of C++ converts a string input to its numeric value.

10. …………………….. members of a class cannot be accessed from the main(), but can be accessed by its derived class.

11. …………………… represents the standard output stream, which is an object of ostream class.

12. …………………………file open mode discards the file’s contents if it exists.

13. Classes from which objects cannot be instantiated are called ……………….. classes.

14. The …………………… operator is used to indicate indirection on a pointer to a structure.

15. A constructor cannot be declared as ……………………….

16. ……………………. function reduces function call overload.

17. In ……………………….., the compiler and the linker directly define the fixed address of the code to be executed on every function call.

18. An …………………….. is a user-defined data type whose values consist of a set of named constants.

19. ……………………. operator is used to dynamically allocate memory.

20. Macros are ………………………
( SET – VII )

1. private 2. colon 3. arguments
4. defining 5. transitive 6. stdprn
7. cerr 8. stdout 9. right
10. class 11. hybrid 12. signature
13. tagname 14. multilevel 15. virtual
16. data encapsulation 17. abstract 18. scope resolution
19. void 20. hierarchical 21. struct
22. operator assignment 23. stderr 24. stdin
25. public 26. data abstraction 27. clog
28. multiple 29. single 30. left
31. variable 32. middle 33. semicolon
34. defining class objects 35. inheritance 36. encapsulation

1. ……………………. refers to hiding physical details and displaying only the needed information.

2. ……………………. provides data security by hiding it from the external world.

3. ……………………. contains data members and methods to operate on these members.

4. ……………………. contains data members only.

5. The member functions, if defined outside the class must use …………………….

6. The class members, by default are ……………………..

7. …………………… is used to define objects of the class.

8. A class declaration ends with a ……………………..

9. Memory to data members is allocated while ………………………

10. Memory to member functions is allocated while …………………….

11. Constructor functions cannot be …………………….

12. The inheritance type where a derived class inherits from many base class is …………………… inheritance.

13. A ………………… class is one that cannot be instantiated.

14. In case of default arguments the arguments may only be defaulted from the ……………………

15. Outputs to the standard error stream are directed to either the ………………. or the …………………… stream objects.

16. The four objects that correspond to the standard devices on the system include ………………,……………….,……………… and …………….

17. Function prototype is function ………………….

18. Constructors do not have any return type not even ………………….

19. Inheritance is …………………….. in nature.

20. A “has-a” relationship between classes represents ……………………. and an “ is-a” relationship between classes represents ………………………
 

( SET – VIII )

1. static 2. publicly 3. base class
4. unary 5. dot(.) 6. arrow(->)
7. new 8. friendship 9. non-member
10. data member 11. auto 12. array
13. private 14. derivation 15. array of objects
16. register 17. member 18. binary
19. privately 20. delete 21. extern
22. abstract 23. protected 24. member
25. derived class 26. nested 27. public
28. base class 29. array of pointers

1. The ………………. declaration specifies that the object can be used between separate transaction units of program.

2. A structure may be dynamically created using the ……………….. operator.

3. The structure pointer operator is …………………….

4. The class from which other class inherits is a ……………………

5. A ………………… function is used to retrieve values of the private data of a class.

6. The protected members are inherited as private when inherited …………………

7. An ………………….. operator when overloaded, takes one argument.

8. A global anonymous union must be declared as …………………..

9. A …………………… class is one that contains another class definition.

10. Use of ………………… variables reduces the size of the program and improves the performance.

11. The default storage class for variables is ……………………

12. …………………… allows the encapsulation of functions within that class alone.

13. ……………………. allows the encapsulation of function with in that class and derived class.

14. When a base class is inherited publicly, the ……………….. members of the base class become the public members of derived class.

15. ……………………. is used to deallocate memory allocated with new.

16. A base class that has a pure virtual member function is an ………………. class.

17. A base class is inherited by …………………..

18. A class contains ………………………. and methods that operate on these.

19. The …………………… operator is used to access the members of a class.

20. An array having class type elements is known as ……………………..
 

( SET – IX )

1. synchronous 2 template 3 class
4. synchronous 5 void 6 unexpected()
7. semantical 8 catch 9 polymorphic class
10. char 11 throw 12 object oriented programming(OOP)
13. try() 14 unsetf() 15 generic class
16. asynchronous 17 template function 18 syntactical
19. object oriented analysis(OOA) 20 int 21 setf()
22. catch() 23 resetf() 24 logical
25. exception handling 26 asynchr-onous 27 static class
28. object oriented design(OOD) 29 virtual function 30 pure virtual function

1. The exception is processed using ………………

2. ………………….. enable us to define generic classes.

3. …………………..helps to identify and manage error conditions during program execution.

4. In exception handling the keyword ……………… implements the return activity.

5. Exceptions are of two kinds, …………………… and ………………………….

6. Errors such as overflow are …………………… exceptions.

7. Keyword interrupt is …………………… exception.

8. The thrown exceptions are caught by the keyword ………………..

9. A function generated from a function template is called a ……………………..

10. The template definition is preceded by the keyword …………………

11. …………………….. refers to specifying requirements in terms of real world objects.

12. …………………….. deriving class hierarchies out of the specification made earlier.

13. …………………….. refers to the implementation of programs using objects in any object oriented programming language.

14. If no appropriate handler is available the function invoked to process the exception is …………………..

15. The template function declaration specifies a generic ……………………

16. The compiler detects …………………….. errors.

17. In C++, main() function returns a value of type …………………….

18. A class that inherits a base class containing virtual function is called ………………………..

19. A …………………….. has no definition is its base class.

20. In C++, the format flags are reset by ………………….
( SET – X )

1. close() 2. scientific 3. seekg()
4. clear() 5. tally() 6. heap
7. reference 8. void pointer 9. asterisk(*)
10. typedef 11. ifstream 12. null character
13. overloaded 14. ios::nocreate 15. tellp()
16. bitwise AND 17. ofstream 18. int pointer
19. virtual 20. anonymous union 21. static
22. getline() 23. ios::noreplace 24. seekp()
25. bitwise OR 26. resetf() 27. null pointer

1. The class ………………….. is used to create the output stream.

2. If file mode parameter is specified as ………………………, the open operation fails if the file already exists.

3. The file mode can combine two or more parameters using ………………… operator.

4. In C++, void pointer can be assigned only to a …………………..

5. The member function ……………………. closes a file that has been opened for file processing.

6. The ……………….. function reads a line terminating with a newline character.

7. The flag ………………… in iostream formats floating point values in scientific form.

8. …………………… moves the get pointer to a specified location.

9. ………………….. gives the current position of the put pointer.

10. The ……………….. and ……………. functions handle the data in binary form.

11. The function ……………….. resets the error state.

12. …………………… function returns true when an input or output operation has failed.

13. ………………….. is an unnamed union in C++.

14. Free store is also referred to as …………………..

15. In C++, the redirection operator is …………………..

16. The …………………. is used for terminating strings.

17. A …………………. is an alias for a variable.

18. To specify a new name to the data type ……………… keyword is used.

19. ……………………. functions implement polymorphism.

20. ……………………. is a pointer that does not point to any data object.
ANSWERS TO FILL UP THE BLANKS

(SET-I)

1.  token                  2.  sensitive              3.  identifiers

4.  octal                   5.  \0n                     6.  string literal

7.  derived               8.  atomic                9.  cout

10.  enumerator        11.  ternary              12.  constant

13.  <<                     14.  comma              15.  semantical

16.  precedence        17.  type casting        18.  sizeof

19.  void                  20.  union
 

(SET-II)

1.  10                       2.  conditional           3.  do..while

4.  goto                    5.  innermost            6.  getchar()

7.  subscript             8.  int                      9.  prototype

10.  reference           11.  auto                  12.  extern

13.  register              14.  <<                     15.  >>

16.  define                17.  initialize             18.  curly brackets

19.  same                 20.  zero
 

(SET-III)

1.  setf()                   2.  width()                3.  unitbuf

4.  iomanip.h            5.  essential              6.  initialization

7.  continue              8.  return                 9.  actual

10.  formal               11.  register              12.  recursive

13.  preprocessor 14.  “iostream.h”           15.  subscript

16.  pointer              17.  unsigned            18.  extensibility

19.  data abstraction        20.  friend
 

(SET-IV)

1.  data abstraction 2.  data encapsulation             3.  class

4.  structure                5.  scope resolution          6.  private

7.  volatile                   8.  semi-colon

9.  instantiated             10.  default

11.  inheritance            12.  public

13.  delete                  14.  signature

15.  polymorphic          16.  zero

17.  one                      18.function overloading

19.  scope resolution    20.  data abstraction
 

(SET-V)

1.  templates        2.  exception handling       3.  template

4.  throw             5.  catch                          6.  try

7.  unexpected()   8.  primitive                     9.  non-primitive

10.  virtual           11.  this                           12.  identity

13.  setbase         14.  class                         15.  structure

16.  seekg()          17.  binding                      18.  virtual

19.  abstraction     20.  static binding
(SET-VI)

1.  fstream.h             2.  aggregation          3.  constructor

4.  subscript             5.  getline()              6.  const

7.  derived               8.  encapsulation       9.  atoi()

10.  protected           11.  cout                  12.  ios::noreplace

13.  abstract             14.  arrow                15.  static

16.  inline                 17.  static binding      18.  enumerator

19.  new                  20.  preprocessor directives
 

(SET-VII)

1.  data abstraction                      2. data encapsulation

3.  class                                     4.  struct

5.  scope resolution operator        6.  private

7.  tag name                               8.  semicolon

9.  defining objects                      10.  defining class

11.  virtual                                  12.  multiple

13.  abstract                               14.  right

15.  cerr, clog

16.  stdout, stdin, stdprn, stderr

17.  signature                              18.  void

19.  transitive

20.  encapsulation, inheritance
 

(SET-VIII)

1.  extern                 2.  new                    3.  arrow(->)

4.  base class            5.  member              6.  privately

7.  binary                 8.  static                   9.  nested

10.  register              11.  auto                  12.  private

13.  protected           14.  public                15.  delete

16.  abstract             17.  derived class      18.  data members

19.  dot(.)                 20.  array of objects.
 

(SET-IX)

1.  catch()                                          2.  templates

3.  Exception Handling                         4.  throw

5.  synchronous & asynchronous           6.  Asynchronous

7.  asynchronous                                8.  catch

9.  template function                           10.  template

11. object oriented analysis(OOA)

12.  object oriented design(OOD)

13.  object oriented programming(OOP)

14.  unexpected()

15.  generic class                              16.  syntactical

17.  int                                             18.  polymorphic class

19.  pure virtual function                    20.  unsetf()
(SET-X)

1.  ofstream                       2.  ios::noreplace   3.  bitwise OR

4.  void pointer                  5.  close()              6.  getline()

7.  scientific                       8.  seekg()             9.  tellp()

10.  write(), read()              11.  clear()            12.  fail()

13.  Anonymous union        14.  heap              15.  asterisk (*)

16.  null character              17.  reference        18.  typedef

19. virtual                          20.  null pointer

 

Tags

‘TRUE’ OR ‘FALSE’ in C++



SAY ‘TRUE’ OR ‘FALSE’

1. C++ is a case-insensitive language.

2. Comments in C++ may be specified by /*..*/ or // or –.

3. The return statement in main() function is optional.

4. Comments can be nested in C++.

5. OOPs (Object Oriented Programming) is a programming approach implementable in C++.

6. A statement in C++ may be syntactically correct but semantically incorrect.

7. The Linker program generates the executable version of the source code.

8. All the library files and header files are searched, when you compile the source code.

9. The value of a local variable is accessible outside a block.

10. C++ supports low-level as well as high level programming.

11. In C++, it is not mandatory to specify a function prototype.

12. Variables may be declared at any place in a C++ program.

13. cin and cout statements may be concatenated.

14. You must define a function prototype if you invoke a function before defining it.

15. int x, y=x; is a valid C++ statement.

16. You can write more than one command in a line.

17. Procedural abstractions represent the objects on which the procedures are acting.

18. You can call standard ‘C’ library functions in a C++ program using an extern ‘C’ statement.

19. void is the default return type of main().

20. cout is extensible i.e. it can handle user defined data types.

21. You could use main as a variable name.

22. The return value of function main() is returned not to another part of the program but to the operating system.

23. Structure is similar to that of class except that it does not contain methods that operate on data members.

24. Variable names of arguments passed to a function are optional in function prototype.

25. An identifier must begin with an alphabet or underscore.

26. #include directive is an essential for each C++ code.

27. A variable needs to be defined before its usage.

28. cout << ‘\n’ ; and cout << “\n” are valid statements in C++.

29. Symbolic constants may be defined using const qualifier but not with #define.

30. By default all float values are casted implicitly to double data type.

31. Assigning a long value to a float can result in round-off error.

32. An array is passed by reference.

33. A constant member function can’t be overloaded with a non-constant object.

34. static and extern variables are created during compilation time before the main() function.

35. const identifiers may be initialized before their usage.

36. The minimum array size needed to hold a string “C++” is 3.

37. A structure declaration ends with a semicolon.

38. You can declare structure objects from main(), even if you don’t specify the tag name, while declaring it outside the main().

39. ‘C’ is an example of string constant.

40. It is not possible to obtain the size of a data type in C++.

41. pow() function finds the square of a number.

42. Unary arithmetic operators have higher precedence then the modulus operator.

43. Relational operators have lower precedence than logical operators.

44. Logical NOT operator has higher precedence than arithmetic operators.

45. A structure variable may be passed as a parameter to a function.

46. Assignment operator (=) may be used with structure variables to assign the value of one structure value to the other.

47. A structure is a user defined type build using data of other types.

48. Memory is allocated when you define a structure.

49. Structures must always be declared globally.

50. Global variables are always defined externally i.e. outside of main() and preceding it.

51. The result of the expression: 7 * 5 / 7 is 0.

52. exit(1) implies abnormal termination of the program.

53. while(condition) must follow the enclosed statement atleast once.

54. for(;;) is a valid looping construct i.e. initialization, conditional and update sections are optional.

55. A pointer variable stores the address of some other variable.

56. It is mandatory to specify break with each case statement in switch() construct.

57. continue is used for an unconditional transfer of control statement.

58. De-reference operator (*) references to the value of a variable following it.

59. In C++, a pointer with the value zero is called NULL pointer.

60. The return value is zero, if memory is not dynamically allocated using new operator.

61. new operator may be used to allocate memory dynamically and that too of any type.

62. x=x+1; is invalid for arrays as you can’t change the value of an array name.

63. Incrementing a pointer variable by 1, fetches the successive memory location irrespective of the data type.

64. Pointers can be compared using relational operators.

65. Pointer de-referencing operator (->) is used to access structure members created dynamically.

66. A static variable persist for the duration of a program.

67. While memory is allocated dynamically, initialization of variables is possible.

68. The return type of new operator is void.

69. for and do..while loops are entry condition loops.

70. If x1 is a variable, then x1+5; is a valid statement in C++.

71. If ptr[3]=5; then ptr[3]+=5; as well as *(ptr+3)+=5; will result in value 10.

72. The value of the k in the expression: int i=10, k=20*i; is 10.

73. The condition: if(y=5){x=1;} else {x=2;} will result in the value of x as 2 if y is 4.

74. Array initialization can be performed only at the time of array declaration.

75. Integer arrays by default are initialized with zero.

76. The default return type of a function is void.

77. Default arguments to functions may be specified in right to left fashion.

78. If structure is passed as function parameter, then the original value remains unchanged.

79. The scope of external variables is the entire program, whereas that of auto is block scope.

80. Macros end with a semicolon.

81. The ability of a function to call itself is recursion.

82. The preprocessor directive #include must be placed before the function main().

83. strstr() checks for the occurrence of a given substring in another string.

84. isupper() function is part of string.h header file.

85. long double data type allocates 10 bytes of memory on a particular machine.

86. If ans=5; cout<<ans++; will print 6 on the screen.

87. Post increment/decrement operators have higher precedence than pre increment/decrement operators.

88. A register declaration is a auto declaration.

89. The storage class needed for a variable x which is to be shared by the function in one file but hidden from other file is static global.

90. Both, structure tag name and structure variable may be omitted simultaneously.

91. Structures may be nested.

92. Functions can return structures.

93. An enumerated data type provides a way to name numbers in symbolic form.

94. enum ans{true, false}; declaration assigns value 1 to true and 0 to false.

95. The default value of variables in enum type may be changed explicitly by the user.

96. An enumerated type defined within a structure has to be accessed using a dot operator, as it is local to the structure.

97. int y=2,507; is an valid assignment statement in C++.

98. In C++, the logical operator AND is symbolized by symbol || and OR by &&.

99. In a switch construct, you cannot use comparison operators with the case clause.

100. C++ creates anonymous variables when you mismatch a variable to a reference.

101. Class member functions are also termed as class methods.

102. Functions defined in a class specification are automatically inline.

103. The member functions of a class must always be defined outside the class definitions.

104. Inline functions are invoked as normal functions.

105. A class can’t have an array as its member.

106. The default class scope is private.

107. A private data member of a class can only be accessed by its member function.

108. A class supports encapsulation, abstraction and data hiding features in C++.

109. Methods in a class can’t be declared as private.

110. A function defined outside a class must precede with inline qualifier to make it inline.

111. #define macro is similar to an inline function.

112. Inline functions are efficient but consume more memory.

113. Memory is allocated when a class is defined.

114. A friend function is a member function.

115. A function as well as a class may be friend of the other class.

116. Memory allocation takes place only when a class object is created.

117. A private data member is accessible to a friend function.

118. A friend function to a class can be listed in either part of a class.

119. The public or private distinction does not apply to friend functions.

120. The public member functions set the class interface.

121. Scope resolution operator defines a function which is not a member function.

122. It is upto the compiler whether to make any function inline or not even after defining it as inline.

123. A constructor function is called when a class object is created.

124. The default return type of constructor function is void.
125. Data members of a class can’t be initialized in the class definition.

126. A static data member must be defined outside the class definition.

127. A constructor function may have a name other than the class name.

128. A default constructor takes one argument.

129. A copy constructor initialize an object with the other one.

130. Constructors may be overloaded.

131. Constructors can only be defined inside a class definition.

132. A constructor function is not a member function.

133. A constructor function can only be defined as public.

134. By default, if no constructor is defined, a default constructor with no parameters is invoked.

135. Constructors may use default arguments.

136. The destructor is the class name preceded by a tilde (~).

137. A destructor is called immediately before the storage for the object is released.

138. A class constructor is called only once, irrespective of object definition.

139. Destructor functions may or may not receive arguments.

140. A destructor can have no return value.

141. Parameterized constructors accept arguments.

142. Constructor arguments are specified while creating class object.

143. A constructor function with default values of all the arguments is a default constructor.

144. Class destructors become necessary when class constructors use new.

145. You can have only one destructor per class.

146. If c1(int x) ; is a class constructor accepting an integer parameter, then c1 obj = 5; is a valid assignment in C++.

147. The fundamental (basic) data types don’t have constructors.

148. Constructors may be called implicitly or explicitly.

149. When an object is passed by value, a copy constructor is invoked.

150. Address of a constructor is not defined.

151. You cannot call a member function from within a constructor.

152. Destructor functions can be inherited.

153. The destructor function may be static.

154. The derived class inherits the constructor and destructor of the base class.

155. In C++, the class scope resolution operator can be used for selecting member functions of the base class as well as data members.

156. In C++, I/O operations are sensitive to data types.

157. Each overloaded function intended to be a friend must be explicitly declared as a friend of the class.

158. In a class, member objects are constructed in the order in which they are declared.

159. Scope resolution operator has the highest precedence.

160. const constructor may be declared for a class.

161. A class with default constructor can’t initialize a class with another object of the same class.

162. The order of destruction of objects is reversed as that of construction.

163. A friend function can’t use an object to invoke the function.

164. A friend class’s member functions can’t access another class’s private members.

165. You can have only one friend function with a particular name and signature per file.

166. If entire class is made a friend of some other class, then all the member functions of that class become friend functions.

167. A friend function can’t access protected members of a class.

168. The keyword friend appears in the prototype declaration of the function and in actual function definition.

169. A function may be a friend of more than one class.

170. Declaring a friend function in private section of a class rather than public alters its meaning.

171. A friend function operates upon the object(s) passed to it as arguments.

172. Telling the compiler in advance, class name defined later, is forward declaration.

173. The class name used in forward declaration may be different from the one actually defined.

174. Scope resolution operator (::) always refers to the file scope variable.

175. When you define a class, memory is allocated for data members as well as member functions.

176. For member functions, memory is allocated only once, i.e. when is class is defined.

177. The memory space is allocated for objects’ data members, only when the class objects are declared.

178. An object may be passed as an argument to a member function, a non-member function and a friend function.

179. A class may be declared as static.

180. A static data member is shared by all the objects of a class.

181. A static data member is visible only within the class.

182. A static data member is accessible outside the class, as its scope is entire program.

183. A static data member may be initialized while defining it.

184. A static data member function accesses only the static data members of a class.

185. Members of a class are public by default.

186. A friend function can’t invoke other friend function.

187. Class data members must always be private.

188. Member-wise assignment of data members of an object takes place through assignment operator.

189. A const member function can’t modify an object data member.

190. A friend function declared inside a class is invoked through class objects.

191. const static data members may be declared.

192. The argument may be passed by value to a copy constructor.

193. Function overloading results in faster execution of programs.

194. If two functions with same name have similar parameters but different return type, they are overloaded.

195. func1(int x) ; func2( unsigned int x1) ; results in compilation error.

196. The compiler looks for the nearest match through promotion in calling overloaded functions.

197. In C++, with default arguments, only the arguments from the right side can be defaulted.

198. A constructor function cannot be overloaded.

199. Function parameter is function signature.

200. Dynamic binding allows to handle class hierarchies in a very simple way.

201. You can’t redefine the minus operator so that it finds the sum of two double numbers instead of finding their difference.

202. You can violate the syntax rules for the original operator while overloading it.

203. You can alter operator precedence while overloading.

204. Scope resolution operator (::) cannot be overloaded.

205. You can’t define new operator symbols while overloading an operator.

206. Subscripting operator ([]) can be overloaded only through member function.

207. the int_array = str_array; statement of C++ is legal, if int_array is an array and str_array is a string.

208. We cannot provide a new definition of assignment by overloading the assignment operator(=).

209. Overloaded operators can be non-member functions.

210. sizeof and conditional operator cannot be overloaded.

211. Default arguments can be used to overload an operator.

212. The NULL pointer is defined in the standard header file stddef.h.

213. You can perform multiplication operation on pointers.

214. The unary operator new returns a pointer to a char type value.

215. The newly allocated memory can be initialized at the time of allocation itself.

216. The scope of an object created using new is entire program.

217. A reference is an alias name for a variable.

218. A function that returns reference can be placed on the left side of an assignment statement.

219. Pointers to different classes cannot be assigned to each other.

220. A function with a parameter that is a reference or pointer to constant invoking member function that has a constant invoking object may still be used with non-constant objects.

221. The value of a pointer to a constant cannot be changed.

222. A structure having a member element that refers to the structure itself is a self-referential structure.

223. A pointer can point to only public members of the class.

224. The unary indirection operator can be used on the left side of an assignment statement.

225. ‘this’ is an implicit pointer.

226. The static member functions may have a ‘this’ pointer.

227. The value of ‘this’ pointer cannot be changed.

228. You can cast a ‘this’ pointer to some other type.

229. Static member functions cannot be accessed by this pointer.

230. It is possible to pass a ‘this’ pointer to friend functions.

231. The dot operator is used to access the public members of the class with a pointer to an object.

232. In C++, functions may return reference.

233. Inheritance is often referred to as ‘is-a’ relationship.

234. A derived class can directly access the private data members of the base class.

235. A derived class can directly access the protected data members of the base class.

236. By default, private members are not inherited.

237. Constructors and Destructors could not be declared virtual.

238. Constructors may not be defined as virtual, but explicit destructors may be defined to be virtual.

239. A pure virtual function is a virtual function that has no implementation in its class.

240. Abstract classes can be instantiated.

241. An abstract class may have more than one virtual function.

242. An abstract base class essentially includes at least one pure virtual function.

243. The ofstream class defines a rich collection of unformatted input functions.

244. Increment operator (++) and decrement operator (–) can be overloaded for prefix as well as postfix form.

245. ** may be overloaded as an exponentiation operator.

246. In C++, input output operations are sensitive to the type of data.

247. this pointer is always implicitly used and can’t be used explicitly.

248. To derive a class from a base class, the default access level is public.

249. C++ views a file as a stream of bytes.

250. Static member functions cannot be accessed by ‘this’ pointer.

251. The <iomanip.h> header file contains information for formatted input/output with parameterized stream manipulators.

252. In C++, outputs to object cerr are unbuffered.

253. Member functions tellp and tellg return the current locations of the put and get pointers respectively.

254. C++ provides both unformatted I/O and formatted I/O operations.

255. Inheritance exhibits transitive nature.

256. When many subclasses inherit from a single base class, it is multiple inheritance.

257. The transitive nature of inheritance is reflected by hybrid inheritance.

258. When inheriting publicly, the derived class can access private members of the base class directly.

259. When inheriting privately, the public and protected members of the base class become private members of the derived class.

260. A privately inherited class may be inherited further.

261. Members intended to be inherited but not intended to be public, should be declared as private.

262. When an object of a derived class is created, the program first calls the constructor for base class and then of derived class.

263. You can pass parameters to a base class constructor through a derived class constructor.

264. You can selectively allow access to some of the base class members when deriving privately.

265. Derivation is friendship.

266. We cannot assign a base class pointer to a derived class pointer.

267. A virtual function can be a static member function.

268. A derived class object is converted to a base class object when used as an argument to a base class member function.

269. If you expect to redefine a function in derived classes, declare it as a virtual function in the base class.

270. The ios class represents general properties of a stream.

271. In C++, output to object clog is unbuffered.

272. The endl manipulator flushes the buffer and inserts a newline.

273. unsetf() member function reads current format flag’s value.

274. In C++, references are same as pointers.

275. A virtual function may be declared a function in another class.

276. An overloaded binary operator can be overloaded for ternary operation.

277. showpoint is an enumerated constant defined in the ios class definition.

278. setprecision is a part of <iomanip.h> header file.

279. precision() function has default value as 2.

280. In C++, << is insertion operator and >> is extraction operator.


Solution Set to TRUE or FALSE

(1) F (2) F (3) T (4) F (5) T
(6) T (7) F (8) T (9) F (10) T
(11) T (12) T (13) T (14) T (15) F
(16) T (17) F (18) T (19) F (20) T
(21) T (22) T (23) T (24) T (25) T
(26) F (27) T (28) T (29) F (30) T
(31) T (32) T (33) T (34) T (35) F
(36) F (37) T (38) F (39) F (40) F
(41) F (42) T (43) F (44) T (45) T
(46) T (47) T (48) F (49) F (50) T
(51) F (52) T (53) F (54) T (55) T
(56) T (57) F (58) F (59) T (60) T
(61) T (62) T (63) F (64) T (65) T
(66) T (67) T (68) T (69) F (70) T
(71) T (72) F (73) F (74) T (75) F
(76) F (77) T (78) F (79) T (80) F
(81) T (82) T (83) T (84) F (85) T
(86) F (87) T (88) T (89) T (90) F
(91) T (92) T (93) T (94) F (95) T
(96) T (97) F (98) F (99) F (100)T

(101) T (102) T (103) F (104) F (105) F
(106) T (107) T (108) T (109) F (110) T
(111) F (112) T (113) F (114) F (115) T
(116) T (117) T (118) T (119) T (120) T
(121) F (122) T (123) T (124) F (125) T
(126) T (127) F (128) F (129) T (130) T
(131) F (132) F (133) F (134) T (135) T
(136) T (137) T (138) F (139) F (140) T
(141) T (142) T (143) T (144) T (145) T
146) T (147) F (148) T (149) T (150) T
(151) F (152) F (153) F (154) F (155) T
(156) F (157) T (158) T (159) T (160) T
(161) F (162) T (163) T (164) F (165) T
(166) T (167) F (168) F (169) T (170) F
(171) T (172) T (173) F (174) T (175) F
(176) F (177) T (178) T (179) F (180) T
(181) T (182) F (183) T (184) T (185) F
(186) F (187) F (188) T (189) T (190) F
(191) T (192) F (193) T (194) F (195) F
(196) T (197) T (198) F (199) T (200) T

(201) T (202) F (203) F (204) T (205) T
(206) T (207) T (208) F (209) T (210) T
(211) F (212) T (213) F (214) F (215) T
(216) F (217) T (218) T (219) T (220) T
(221) T (222) T (223) T (224) T (225) T
(226) F (227) T (228) T (229) T (230) F
(231) F (232) T (233) T (234) F (235) T
(236) T (237) F (238) T (239) T (240) F
(241) T (242) T (243) F (244) T (245) F
(246) F (247) F (248) F (249) T (250) T

(251) T (252) T (253) T (254) T (255) T
(256) F (257) F (258) F (259) T (260) F
(261) F (262) T (263) T (264) T (265) F
(266) F (267) T (268) T (269) T (270) T
(271) F (272) T (273) F (274) F (275) F
(276) T (277) T (278) T (279) F (280) T

Tags

Multiple choice questions in C++




Multiple choice questions in C++ (With answers)

1. An entity representing some characteristics and behaviour is-
a) object
b) class
c) struct
d) none of the above

2. Which of the following is not the feature of OOPs?
a) Data Encapsulation
b) Inheritance
c) Polymorphism
d) None of the above
3. The wrapping up of data and functions into a single unit is
a) Data Abstraction
b) Data Encapsulation
c) Both (a) & (b)
d) None of the above

4. Which of the following feature supports reusability and extensibility of classes?
a) Inheritance
b) Overloading
c) Polymorphism
d) None of the above

5. Inheritance is ………..in nature.
a) Intransitive
b) Transitive
c) Both (a) & (b)
d) None of the above


6. ………… is the ability for a message or data to be processed in more than one form
a) Class
b) Abstraction
c) Polymorphism
d) None of the above

7. The smallest individual unit in a program is ………
a) Keyword
b) Identifier
c) Token
d) None of the above

8. Which of the following features of procedure oriented programming is false
a) Large programs are divided into small or units called functions.
b) Employs bottom-up approach in program design.
c) Most of the functions share global data.
d) None of the above.

9. Which of the following features of object oriented programming is false?
a) Data is hidden and is not available to external functions.
b) New data & functions can be added easily.
c) Objects may communicate with each other through functions.
d) Emphasis is on the procedure rather than data.

10. The following is the C++ style comment
a) //
b) /*..*/
c) —
d) None of the above




11. Which of the following statements is false?
a) Every C++ program must have a main().
b) In C++, white spaces and carriage returns are ignored by the compiler.
c) C++ statements terminate with semicolon.
d) Main() terminates with semicolon.

12. An identifier in C++
a) Must begin with a letter only
b) Is not differentiated by cases
c) Contains all characters as significant
d) None of the above

13. 010 is an example of
a) decimal constant
b) octal constant
c) hexadecimal constant
d) None of the above

14. A sequence of characters surrounded by double quotes is
a) Character literal
b) String literal
c) Both (a) & (b)
d) None of the above

15. The following data type specifies an empty set of values
a) Void
b) Int
c) Char
d) None of the above




16. ………. Provides a value for a variable
a) declaration statement
b) assignment statement
c) definition statement
d) None of the above

17. A collection of variables referred under one name
a) Structure
b) Class
c) Union
d) None of the above

18. A memory location shared by two or more different variables
a) Structure
b) Class
c) Union
d) None of the above

19. The constants defined using enum keyword are
a) Symbols
b) Enumerators
c) Keywords
d) None of the above

20. The operator ?: is
a) Logical operator
b) Relational operator
c) Conditional operator
d) Arithmetic operator



21. A loop containing other loop is
a) Nested
b) Inner
c) Outer
d) None of the above

22. The following statement forces the next iteration of the loop to take place
a) break
b) continue
c) goto
d) None of the above

23. gets() function is available in
a) stdio.h
b) string.h
c) ctype.h
d) stdlib.h

24. In C++, the statements are enclosed within
a) parenthesis
b) square brackets
c) curly brackets
d) None of the above

25. The following tells the compiler where the program begins
a) Function prototype
b) Forward declaration of class
c) main()
d) None of the above



26. << operator is
a) stream insertion operator
b) stream extraction operator
c) left shift operator
d) None of the above

27. “H” is an example of
a) character literal
b) string literal
c) variable
d) None of the above

28. Which of the following statements regarding comments is false?
a) /*..*/
b) Comment beginning with // extends to the end of the line
c) Comments may be nested
d) Comments are used to describe a program

29. C++ is
a) Procedural programming language
b) Structural programming language
c) Object oriented programming language
d) None of the above

30. y=x=2; in C++ will result in
a) compilation error
b) runtime error
c) assignment of value to x then to y
d) None of the above



31. In C++, ………. is the statement terminator
a) semicolon
b) colon
c) new line
d) None of the above

32. Modules operator (%) has higher precedence than
a) Divide (/) operator
b) Multiply (*) operator
c) Negation (unary minus)
d) Bitwise left shift operator

33. The result of the following statement is
int y = 7;
int ans = ++y;
cout<<”ans=”<<ans;
cout<<”y”<<y;

a) ans=7, y=7
b) ans=8,y=7
c) ans=8,y=8;
d) none of the above

34. Consider the following if construct
If(x=0)
cout<<”Inside loop!”;
cout<<”Outside loop”;
The result of the above code segment is.

a) inside loop
b) outside loop
c) both (a) & (b)
d) none of the above

35. The result of 2 & 3 is
a) 2
b) 3
c) 5
d) none of the above



36. Which of the following statements regarding enumerators is false?
a) Enumeration is an alternative method for naming integer constants/
b) An enumerator value can’t be changed in a program
c) An integer value may be assigned to an enumerated variable
d) An enum defined within a structure is local to the structure

37. Which of the following statements is false?
a) typedef defines new data types
b) Using typedef does not replace the standard C++ data type name with the new name
c) The new name defined by typedef, can be used as a type for another typedef
d) None of the above

38. Data members and member functions are enclosed within
a) class
b) structure
c) union
d) None of the above

39. Inline functions are
a) Declared in the class defined outside the class
b) Defined outside the class using keyword intime
c) Defined inside the class using keyword inline
d) None of the above

40. The default class access scope is
a) Private
b) Public
c) Protected
d) None of the above



41. The default scope for a structure is
a) Private
b) Public
c) Protected
d) None of the above

42. The private data members of a class are accessible
a) Directly to objects of that class
b) Only to the member functions
c) To any function defined outside a class
d) None of the above

43. The objects can directly access
a) Public members
b) Private members
c) Both (a) & (b)
d) None of the above

44. The following is a valid statement in C++
a) int x=(int)2.50;
b) int x=int(2.50);
c) Both (a) & (b)
d) None of the above

45. Which of the following operator can be overloaded
a) Member access operator ( . & .*)
b) Conditional operator (?:)
c) Scope resolution operator (::)
d) None of the above



46. Using same function name to perform different tasks is
a) Function polymorphism
b) Runtime polymorphism
c) Function prototype
d) None of the above

47. Default argument is
a) Specified in function definition
b) Specified in function declaration
c) Specified from left to right
d) None of the above

48. What is wrong with the following statement?
float s_interest (float principal, int rate=0.25, int time);

a) variables must not be specified in function prototype
b) arguments may only be defaulted from right to left
c) the default value must be specified when making a function call
d) none of the above

49. Which of the following statements regarding function overloading is not true.
a) If is used to handle different data types at one place
b) When making a function call, if no exact match is found, promotion is the only criteria to find a match.
c) The default arguments can not be used instead of overloading
d) Unrelated functions should not be overloaded

50. The private members of a class implement the OOP concept of
a) Data abstraction
b) Data hiding
c) Message passing
d) None of the above



51. When a member function of a class call another member function, it is
a) Nesting of classes
b) Nesting of functions
c) Nesting of objects
d) None of the above

52. A function defined inside a class is called
a) A class function
b) A friend function
c) A member function
d) None of the above

53. Information is made shareable through
a) inheritance
b) data encapsulation
c) data abstraction
d) none of the above

54. Functions can returns
a) arrays
b) reference
c) object
d) all of the above

55. The memory for date members is allocated
a) When a class is defined
b) When an object is initialized
c) When an object is created
d) None of the above



56. The memory for member functions is allocated
a) When a class is defined
b) When a object is created
c) When an object is initialized
d) None of the above

57. The dot operator relates
a) A class member and a class object
b) A class object and a class
c) A class and a member of that class
d) A class object and member of that class

58. A class having another class definition is
a) Nested class
b) Subordinate class
c) Enclosing class
d) None of the above

59. A class whose member functions are friends of other class is
a) Friend class
b) Abstract class
c) Virtual class
d) None of the above

60. The data members of a class are initialized
a) in class definition
b) by a non-member function
c) through constructor function when a class object is created
d) none of the above



61. A constructor function is
a) A friend function to a class
b) A member function with the same name as its class
c) A non-member function
d) None of the above

62. An enumerated type is composed of
a) Integer values with user defined name
b) Variables of different data types
c) Constant numeric values
d) None of the above

63. In C++, the arguments by default are passed by
a) call be reference
b) call be value
c) both (a) & (b)
d) none of the above

64. ? is an example of
a) unary operator
b) binary operator
c) ternary operator
d) none of the above

65. new operator is used
a) to define a new variable
b) to create a new data type
c) to allocate memory dynamically
d) none of the above



66. A constructor function is generally defined
a) In the public section of a class
b) In the private section of a class
c) In the protected section of a class
d) None of the above

67. A class having no public constructors is
a) A private class
b) A public class
c) An abstract class
d) None of the above

68. If a constructor function is defined in private section of a class, then
a) The object cannot be created
b) Only member functions and friends may declare objects of the class
c) Both (a) & (b)
d) None of the above

69. A constructor with no argument is
a) Default constructor
b) Parameterized constructor
c) Copy constructor
d) None of the above

70. If default arguments are provided to a constructor function, then it becomes
a) Default constructor
b) Copy instructor
c) Parameterized constructor
d) None of the above



71. The class of which the objects are not instantiated is
a) Abstract class
b) Virtual class
c) Static class
d) None of the above

72. && denotes
a) logical OR
b) logical AND
c) Bitwise AND
d) None of the above

73. The parameterized constructor
a) Needs initial values as arguments during creation of an object
b) Can be invoked explicitly only
c) Can be invoked implicitly only
d) None of the above

74. Explicit call to a constructor means
a) Providing the constructor name explicitly to invoke it
b) Not providing the construction name at all
c) Is the shorthand method
d) None of the above

75. Classes in C++ are
a) Fundamental data type
b) Primitive data type
c) Desired data type
d) None of the above



76. A copy constructor is called
a) When an object is defined and initialized with another object
b) When an object is passed by value
c) When a function returns an object
d) All of the above

77. Which of the following regarding constructor function is false?
a) Constructor functions don’t have return type, not even void
b) Constructors can’t be inherited
c) We can refer to their addresses
d) Constructors cannot be virtual

78. If new operator is used, then the constructor function is
a) Parameterized constructor
b) Copy constructor
c) Dynamic constructor
d) Default constructor

79. Which of the following statements regarding constructor is false?
a) A constructor may be defined static
b) Constructor can have default arguments
c) Member functions may be invoked from within a constructor
d) None of the above

80. The antonym of constructor is
a) Creator
b) Destructor
c) Destroyer
d) None of the above



81. Variable …………. of void type
a) May be declared
b) Cannot be declared
c) Can be initialized
d) None of the above

82. A destruction function
a) Takes no argument and has no return type not even void
b) Has name similar to that of class, preceded by tilde(~) symbol
c) Is used to destruct an object, constructed through constructor function
d) All of the above

83. Which of the following statements regarding destructor function is false?
a) Destructors do not accept any arguments, nor do they return any values
b) Destructors can be inherited
c) Member functions may be called from within a destructor
d) Destructor functions are called automatically when an object is destroyed

84. Function overloading
a) Involves several function definitions under one name, but different argument types
b) Implements polymorphism
c) Reduces the number of comparison in a program, hence increases the execution speed of a program
d) All of the above

85. The signature of function is
a) The number & type of arguments
b) The return type of a function
c) The class definition
d) None of the above



86. Overloading of constructor function
a) is similar to function overloading
b) different from an overloaded function as it can’t return a value
c) not permitted in C++
d) none of the above

87. The binding of a function call at runtime is
a) Static binding
b) Early binding
c) Late binding
d) Runtime binding

88. The process of giving special meaning to an operator is
a) Operator overloading
b) Operator mechanism
c) Operator definition
d) None of the above

89. The function used to define the task assigned to an operator is
a) Virtual function
b) Operator function
c) Static function
d) None of the above

90. The following operators can not be overloaded
a) Unary operator
b) Binary operator
c) Ternary operator
d) None of the above



91. Which of the following statements regarding operator overloading is not true?
a) New operators cannot be created while overloading
b) The semantics of an operator cannot be changed while overloading
c) Subscript operator([]) can be overloaded
d) None of the above

92. Which of the following statements can be overloaded?
a) Size of operator
b) Scope resolution operator (::)
c) Class member access operator (->)
d) Pointer to member operator

93. Operator functions
a) Can return a value
b) Cannot return a value
c) May return values of limited data types
d) None of the above

94. While overloading, a unary operator
a) Takes no arguments
b) Takes one argument
c) Takes two arguments
d) None of the above
95. While overloading, a binary operator
a) takes no argument
b) takes one argument
c) takes two arguments
d) none of the above



96. Which of the following operators cannot be overloaded?
a) increment and decrement operator
b) function call operator, ()
c) subscript operator, []
d) none of the above

97. When an arithmetic assignment operator is overloaded, the result
a) goes in the object to the left of the operator
b) goes in the object to the right of the operator
c) goes in the object of which the operator is a member
d) none of the above

98. The function that overloads as operator, precedes with the keyword
a) function
b) operator
c) virtual
d) static

99. The symbol **
a) can be overloaded
b) cannot be overloaded as it is not a C++ operator
c) cannot be overloaded, as on overloading its meaning shall be changed
d) none of the above

100. The stream insertion and extraction operators should be overloaded as
a) friend functions
b) member function
c) non member functions
d) none of the above



101. The following operators cannot be overloaded
a) scope resolution operator
b) size of operator
c) conditional operator
d) all of the above

102. The operator definition precedes with the keyword class
a) class
b) operator
c) overload
d) none of the above

103. The operator function
a) is declared in the public section of the class
b) may be a member function or a friend function
c) both (a) & (b)
d) none of the above

104. The operator functions may be invoked
a) implicitly
b) explicitly
c) both (a) & (b)
d) none of the above

105. The following operator can’t be overloaded
a) unary
b) binary
c) ternary
d) none of the above



106. Which of the following statements regarding operator overloading function is false?
a) While overloading, the semantics of an operator cannot be changed.
b) The operator precedence cannot be changed while overloading.
c) The overloaded operator must have at least one operand that is of user-defined type.
d) You can create new operator symbol.

107. The following operators cannot be overloaded.
a) Logical AND (&&)
b) Subscript operator ([])
c) Equality operator (==)
d) none of the above

108. A unary operator when overloaded takes
a) no operand
b) one operand
c) two operands
d) none of the above]

109. The no of arguments required when overloading through friend functions is
a) Zero
b) One
c) Two
d) None of the above

110. Which of the following statements regarding operator overloading is false?
a) friend function cannot be used to overload certain operators.
b) Unary operators overloaded by means of friend functions takes no argument
c) Binary operators must explicitly return a value
d) The syntax rules of the operators cannot be overridden.



111. The following feature supports extensibility and reusability of classes
a) function overloading
b) inheritance
c) operator overloading
d) data encapsulation

112. The process of deriving a class from another derived class is
a) single inheritance
b) multilevel inheritance
c) multiple inheritance
d) none of the above

113. When a derived class inherits only from one class and is not further inherited is
a) single inheritance
b) multiple inheritance
c) multilevel inheritance
d) hybrid inheritance

114. When a derived class inherits from may base classes it is
a) multilevel inheritance
b) single inheritance
c) multiple inheritance
d) none of the above

115. Inheritance is ……….. in nature
a) transitive
b) intransitive
c) both (a) & (b)
d) none of the above



116. ……………. variables cannot be declared
a) structure
b) pointer
c) void
d) class

117. When a subclass inherits from multiple base classes, which inherits from a single class, the inheritance type is
a) single inheritance
b) hybrid inheritance
c) multilevel inheritance
d) multiple inheritance

118. When one class inherits from the base class, then the original class is called
a) base class
b) derived class
c) sub class
d) none of the above

119. The default visibility mode while inheriting is
a) private
b) public
c) protected
d) none of the above

120. The class intended to be a base class should use visibility mode as
a) public
b) protected
c) private
d) Both (a) & (b)



121. Operator overloading is
a) making c++ operators work with objects
b) giving c++ operators more than they can handle
c) giving new meaning to existing c++ operators
d) making new c++ operators

122. To convert from a user defined class to a basic type, you would most likely use
a) a built-in conversion function
b) a one-argument constructor
c) an overloaded-operator
d) a conversion function that’s member of the class

123. The members of a class
a) by default are public
b) by default are private
c) are made private by declaring as private
d) none of the above]

124. The following symbol indicates the derived class is derived from the base class
a) ::
b) :
c) ->
d) none of the above

125. When a base class publicly inherited
a) the public members of the base class are inherited as private
b) the private members are inherited as private
c) the protected members are inherited as protected
d) none of the above



126. When a base class is privately inherited by derived class
a) the public members of the base class becomes the private members of the derived class
b) the private members are not inherited
c) the protected members of the base class becomes the private members of the derived class
d) All of the above

127. Only one copy of the class is inherited, when it is defined as
a) virtual
b) static
c) public
d) none of the above

128. A class that acts only as a base class and is not used to create objects is
a) parent class
b) super class
c) abstract class
d) none of the above

129. The version of a virtual function actually gets called during runtime is based solely up in the type of the object that is
a) being instantiated and processed by the function
b) in the derived class
c) being pointed to by a base class pointer
d) being passed to the function

130. In multiple inheritance, the base classes are constructed
a) in the order of declaration in the derived class
b) in the order of declaration in the program.
c) in the order of definition of a class
d) none of the above



131. When an object of a derived class is created
a) derived class constructor is called followed by base class constructor
b) base class constructor is called followed by derived class constructor
c) base class constructor is not called at all
d) none of the above

132. The derived class constructor
a) never passes any values to base class constructor
b) is responsible for passing the entire test of arguments needed by base class constructors
c) can pass arguments only to one base class constructor function
d) none of the above

133. A virtual base class
a) allows to inherit more than one copy of the base class members
b) strict the path of inheritance
c) is qualified as virtual in base class definition
d) none of the above

134. When a base class is inherited publicly
a) the private members of the base class are not accessible
b) the derived class can directly access the private members of the base class
c) the derived class can access the private members only through the member function of the base class
d) none of the above

135. When two or more classes are used within another class definition, it is
a) inheritance
b) aggregation
c) both (a) & (b)
d) none of the above



136. Composition is referred to as
a) “is a” relationship
b) “has a” relationship
c) both (a) & (b)
d) none of the above

137. Inheritance is referred to as
a) “is a” relationship
b) “has a” relationship
c) Both (a) & (b)
d) none of the above

138. An explicitly defined destructor function
a) may be virtual
b) may not be virtual
c) both (a) & (b)
d) None of the above

139. The copy operation by a simple assignment causes in some cases
a) no effect
b) hollow copy
c) copy exactly the same as original
d) creates new

140. Public data members can be accessed
a) only from the base class itself
b) both form the base class and from its derived class
c) from the class which is a friend of the base class
d) none of the above



141. A static automatic variable is used to
a) make a variable visible to several function
b) make a variable visible only to one function
c) converse memory when a function is not executing
d) retain a value when a function is not executing

142. The stacks data structure are based on
a) LIFO
b) FILO
c) FIFO
d) None of the above

143. Queues are based on
a) LIFO
b) FILO
c) FIFO
d) None of the above

144. & operator is
a) indirection operator
b) Logical AND
c) address operator
d) none of the above

145. int *ptr[10]; is
a) an array of 10 int pointers
b) a pointer of 10 int elements
c) an array of 10 elements returning an int value
d) none of the above



146. A structure that refers to itself is a
a) nested structure
b) recursive structure
c) self-referential structure
d) none of the above

147. With in …….scope class member may be referenced simply by their names
a) class’s
b) object’s
c) program
d) none of the above

148. To point to the address of any pointer variable cast the pointer to
a) char *
b) int *
c) void *
d) none of the above

149. Destructors are called
a) in the same order of constructor calls
b) in the reverse order of constructor calls
c) in any random order
d) none of the above

150. The advantage of declaring a virtual function as pure is
a) you can avoid making the class an abstract class
b) you force any derived class to define its own implementation
c) programs runs faster
d) early binding can be achieved

Solution Set to Multiple Choice Questions

(1)         A          (2)         D          (3)         B          (4)         A

(5)         B          (6)         C          (7)         C          (8)         B

(9)         D          (10)       A          (11)       D          (12)       C

(13)       B          (14)       B          (15)       A          (16)       B

(17)       A          (18)       C          (19)       B          (20)       C



(21)       A          (22)       B          (23)       A          (24)       C

(25)       C          (26)       A          (27)       B          (28)       C

(29)       C          (30)       C          (31)       A          (32)       C

(33)       C          (34)       B          (35)       A          (36)       C

(37)       A          (38)       A          (39)       B          (40)       A



(41)       B          (42)       B          (43)       A          (44)       C

(45)       D          (46)       A          (47)       B          (48)       B

(49)       C          (50)       B          (51)       B          (52)       C

(53)       A          (54)       D          (55)       B          (56)       A

(57)       D          (58)       C          (59)       A          (60)       C



(61)       B          (62)       A          (63)       B          (64)       C

(65)       C          (66)       A          (67)       A          (68)       C

(69)       A          (70)       A          (71)       A          (72)       B

(73)       A          (74)       A          (75)       C          (76)       D

(77)       C          (78)       C          (79)       A          (80)       B

(81)       B          (82)       D          (83)       B          (84)       D



(85)       A          (86)       B          (87)       C          (88)       A

(89)       B          (90)       C          (91)       D          (92)       C

(93)       A          (94)       A          (95)       B          (96)       D



(97)       A          (98)       B          (99)       B          (100)      A

(101)      D          (102)      B          (103)      C          (104)      C

(105)      C          (106)      D          (107)      D          (108)      B

(109)      C          (110)      B          (111)      B          (112)      B

(113)      A          (114)      C          (115)      A          (116)      C

(117)      B          (118)      A          (119)      A          (120)      D



(121)      C          (122)      D          (123)      B          (124)      B

(125)      C          (126)      D          (127)      A          (128)      C

(129)      C          (130)      A          (131)      B          (132)      B



(133)      C          (134)      C          (135)      B          (136)      B

(137)      A          (138)      A          (139)      B          (140)      C

(141)      C          (142)      A          (143)      C          (144)      C



(145)      A          (146)      C          (147)      A          (148)      C

(149)      B          (150)      B

Tags

Inheritance in C++



Inheritance in C++

Inheritance is the property by virtue of which one class passes over its properties to another class without necessitating modification in the main class.  The class that inherits its properties to other class is called the base class whereas the class that receives the properties of the base class is called derived class.  Inheritance supports extensibility of classes, since new features may be added to existing classes without modifying them, by inheriting them to a new derived class, where derived class is defined to contain new additional features, other than the base class.  Inheritance types may be-

  • Single Inheritance
  • Multilevel Inheritance
  • Multiple Inheritance
  • Hierarchical Inheritance
  • Hybrid Inheritance

1.  Single Inheritance:  In single inheritance, a base class inherits its features to a derived class.

In the above figure the base class inherits its features to the derived class.  C++ code for single inheritance is as follows:

class Base
{int x;
public:
void getx();
void putx();
};

class Derived : public Base
{int y;
public:
void gety();
void puty();
};

void main()
{Derived dobj;
dobj.getx();
dobj.gety();
dobj.putx();
dobj.puty();
}

Inheritance type may be public, private or protected.  Private members of a class are never inherited.  When inheritance type is public, public members of the base class are inherited as public and protected members are inherited as protected.  When inheritance type is private, public members as well as protected members are inherited as private.  When inheritance type is protected, public members as well as protected members are inherited as protected.

 

2.  Multilevel Inheritance:  If a base class inherits its features to a derived class and the derived class further inherits its own properties and those inherited from base to another derived, the type of inheritance is called multilevel inheritance.

For example: 


class grandfather
{ int x;
public:
void getx();
void putx();
};

class father : public grandfather
{int y;
public:
void gety();
void puty();
};

class son : public father
{int z;
public:
void getz();
void putz();
};

void main()
{son s;
s.getx();
s.gety();
s.getz();
s.putx();
s.puty();
s.putz();
}

3. Multiple Inheritance:  If a derived class attains properties from more than one base class, then the type of inheritance is called multiple inheritance.

For example:


class base1

{ int x;
public:
void getx();
void putx();
};

class base2
{int y;
public:
void gety();
void puty();
};

class derived : public base1, public base2
{int z;
public:
void getz();
void putz();
};

void main()
{derived s;
s.getx();
s.gety();
s.getz();
s.putx();
s.puty();
s.putz();
}

4. Hierarchical Inheritance:  If inheritance forms a hierarchy, such that a class may inherit its properties at many levels as defined in the hierarchy, the type of inheritance is called hierarchical inheritance.

For example:


 

5. Hybrid Inheritance:  Two or more inheritance types combine together to result in hybrid inheritance.  Some situations may arise when two or more types are required together to define solution to a given problem, such a situation results in hybrid inheritance.  An example of hybrid inheritance is demonstrated in the following figure:

The above figure is a combined representation of multiple inheritance and multilevel inheritance.  For the base classes base1 and base2 inheriting to derived1, the inheritance type is multiple inheritance, but for the remaining part is multilevel inheritance.  This is called hybrid inheritance.

 

Tags

Default arguments in C++ and its constraints




Default arguments in C++ and its constraints

Default Arguments:  The values given to the arguments of the function may be defaulted by supplying the variables with default values at the time of declaring a function.  If the function is invoked without specifying the argument’s value, the default value is assumed for the variable.  Thus, default arguments prove useful in C++ for applications where default values for values may be considered, as for pie (p), default value is 3.14, that may be supplied at the time of declaring the function as follows:

float volume(float r, float h, float pie=3.14);

After default value is supplied to the argument pie, the following funtion invocation statement will work-

float result;
result = volume(3.5,4.5);

such that r receives 3.5, h receives 4.5 and the variable pie receives the default value given in prototype i.e. 3.14.

The constraint for the default arguments is that argument can only be defaulted from right to left.  Thus, the following function declaration with default argument results in an error:

float volume(float r, float pie=3.14, float h);

Default arguments are useful in situations where default values must be supplied automatically with writing them explicitly.

Tags

Exception handling and its classification in C++



Exception handling and its classification in C++

Exception Handling:  The error handling mechanism of C++ is generally referred to as exception handling.  C++ provides a mechanism of handling errors in a program.

Generally exceptions are classified into synchronous and asynchronous exceptions.

  1. Synchronous Exceptions:  The exceptions which occur during the program execution due to some fault in the input data or technique that is not suitable to handle the current class of data, within the program are known as synchronous exceptions.  For example: errors such as out of range, overflow, underflow and so on belong to the class of synchronous exceptions.
  2. Asynchronous Exceptions:  The exceptions caused by events or faults unrelated (external) to the program and beyond the control of the program are called asynchronous exceptions.  For example: errors such as keyboard interrupts, hardware malfunctions, disk failure and so on belong to the class of asynchronous exceptions.

The exception handling mechanism of C++ is designed to handle only synchronous exceptions within a program.

This is done by throwing an exception.  The exception handling mechanism uses three blocks: try, throw and catch.  The try-block must be followed immediately by a handler, which is a catch block.  If an exception is thrown in the try block, the program control is transferred to the appropriate exception handler.  The program should attempt to catch any exception that is thrown by any function.  Failure to do so may result in abnormal program termination.

Exception Handling Constructs:

(1)  throw:- The keyword throw is used to raise an exception when an error is generated in the computation.

(2)  catch:-  The exception handler is indicated by the catch keyword.  It must be used immediately after the statements marked by the try keyword.

(3)  try:-  The try keyword defines the boundary within which an exception can occur.

Thus, the error handling code must perform the following tasks:-

  1. Detect the problem causing exception. (Will hit the exception).
  2. Inform that an error has occurred.  (Throw the exception).
  3. Receive the error information (Catch the exception).
  4. Take corrective actions. (Handle the exception).


For example:  (Divide operation validation)

int division(int n1, int n2)
{
if(n2==0)
throw n2;
else
return n1/n2;
}

int main()
{
————
————
————
try
{
result=division(n1,n2);
}
catch(int)//exception handler block
{cout<<”Exception raised! Division Error…!”;
return -1;
}
————
————
}

 

Tags

Syntax for creating user defined manipulators in C++




Syntax for creating user defined manipulators in C++

C++ provides a set of predefined manipulators. The header file iomanip.h header file contains these manipulators. Moreover, you can design your own manipulators in C++ to suit specific purpose. The user defined manipulators are defined as follows:

ostream & manipulator(ostream & ostr)
{
set of statements;
return ostr;
}

Consider the following example which creates a user defined manipulator named curr for displaying Rs. and sets the precision to 2.

#include <iostream.h>
#include <iomanip.h>

ostream & curr(ostream & ostr)
{
cout<< setprecision(2);
cout<<“Rs. “;
return ostr;
}

void main()
{
float amt = 4.5476;
cout<<curr<<amt;
}

//Output: Rs. 4.55

 

Tags

Use of manipulators in C++




Use of manipulators in C++

Manipulators are stream functions available in iomanip.h header file and are used to change the default formats of input and output.  These are used with stream insertion and extraction operators.  They are used for defining a specified format of input and output.  They provide features similar to that of ios member functions.  Moreover, manipulators may be concatenated to result in a single statement.  Some of the standard manipulators available in iomanip.h header file are endl, setw, setfill, hex, oct, dec, setprecision, flush, setiosflags etc.  Manipulators are different from ios member functions as manipulator does not return the previous format state as is the case with ios member functions.

Consider the following example:

#include <iostream.h>
#include <iomanip.h>

void main()
{
float x = 5.45;
cout<<setw(10);
cout<<setprecision(4);
cout<<setfill(‘*’);
cout<<x<<endl;
}

OUTPUT:

******5.45

Consider another example:

#include <iostream.h>
#include <iomanip.h>

void main()
{
int n=52; //decimal number
cout<<endl<<“Decimal Number=”<<dec<<n;
cout<<endl<<“Hexadecimal Number=”<<hex<<n;
cout<<endl<<“Octal Number=”<<oct<<n;
}

Output:

Decimal Number=52
Hexadecimal Number=34
Octal Number=64

Tags

Template class in C++



Template class in C++

A class which is declared such that it can operate on different data types is referred to as a template class.  It is a generic class defined to support various similar operations on different data types.  For example: a class may be created with a data member, such that it can operate upon any type of data member either int, float or char or any other type.  Whenever we require to generalize the definition of a class for various data types used in C++, we may prefer using class templates, as it gives a more general definition for a class.

To declare a template class, we have to use the keyword template followed by class name i.e. template <class nmofclass>, where template and class are keywords and nmofclass is the userdefined name given to a generic class definition. 

An example to illustrate the use of template class is given below:

template <class sample>
class abc
{
sample x;
public:
void getx(){cout<<”Enter x?”;cin>>x;}
void putx(){cout<<”x=”<<x;}
};

The data type is specified when the object of the class is created in the manner specified below:

abc <int> obj1;
// class that contains an int variable.
abc <float> obj2;
// class that contains a float variable.

The complete program is as follows:

#include <iostream.h>
#include <conio.h>

template <class sample>

class abc
{
sample x;
public:
void getx()
{
cout<<“\nEnter x?”;
cin>>x;
}
void putx()
{
cout<<“\nx=”<<x;
}
};

void main()
{
clrscr();
abc <int> obj1;
cout<<“\nWorking on integer…!”;
obj1.getx();
obj1.putx();

abc <float> obj2;
cout<<“\n\nWorking on float…!”;
obj2.getx();
obj2.putx();
getch();
}

Thus class templates are required to create generic classes that can refer to any user-defined data type.

 

Tags

How is polymorphism achieved at compile time in C++




How is polymorphism achieved at compile time in C++

Polymorphism, in C++, is implemented through overloaded functions and overloaded operators. Function Overloading is also referred to as functional polymorphism. The same function can perform a wide variety of tasks. The same function can handle different data types. When many functions with the same name but different argument lists are defined, then the function to be invoked corresponding to a function call is known during compile time. When the source code is compiled, the functions to be invoked are bound to the compiler during compile time, as to invoke which function depending upon the type and number of arguments. Such a phenomenon is referred to early binding, static linking or compile time polymorphism.

For example:

#include <iostream.h>

//function prototype

int multiply(int num1, int num2);
float multiply(float num1, float num2);

void main()
{
//function call statements

int ans1=multiply(4,3);
// first prototype is invoked as arguments
// are of type int

float ans2 = multiply(2.5, 4.5);
//second prototype is invoked
//as arguments are of type float
}

The compiler checks for the correct function to be invoked by matching the type of arguments and the number of arguments including the return type. The errors, if any, are reported at compile time, hence referred to as compile time polymorphism.

Tags

x Close

Like Us On Facebook