Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 204 - 205 of 354

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 204

C & C Plus Plus
Edit

Describe in Detail

Essay▾
  1. main ()
  2. {
  3.     staticintvar =5;
  4.     printf ( “%d” var--);
  5.     if (var)
  6.     main ();
  7. }

Explanation

  • In a program
Table Shows the Program
static int var = 5Given static storage class
printf ( “% d” var-)Change the value of a static variable
if (var)Check the variable is available or not
main () ;Main is also treated like any other ordinary function, which can be called recursively
  • So, the first time static int var = 5.
  • Than print 5 and decrease the value , and check var are available or not
  • Var are available go to the main () function
  • Same process are continuously when var value was empty
  • So, the answer is 5 4 3 2 1.

Question 205

C & C Plus Plus
Edit

Describe in Detail

Essay▾

Justify the use of virtual constructors in c ++ .

Explanation

  • Constructors are special functions for initializing of every object.
  • Compiler arranges to call the constructor whenever an object is created.
  • Constructors initialize object members after storage is allocated.
  • Constructor has same name as that of class, and constructors never have return type.
  • Constructors are defined either inside the class definition or outside class definition using class name and scope resolution:: operator.
Given the Image is Constructor Declaration and Definition
  • Constructors are of three types:
    • Default constructor
    • Parameterized constructor
    • Copy constructor

Developed by: