Languages [TCS Placement]: Sample Questions 100 - 101 of 131

Get unlimited access to the best preparation resource for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 100

Question

MCQ▾

Which of the following concept of oops allows compiler to insert arguments in a function call if it is not specified?

Choices

Choice (4)

a.

Call by reference

b.

Call by value

c.

Call by pointer

d.

Default arguments

Answer

d.

Explanation

  • “Default arguments” allows compiler to insert arguments in a function call not specified by the caller.
  • Value of default argument is provided in function declaration and automatically assigned by the compiler if caller of the function does not provide a value for the argument with default value.
  • Following simple C ++ example demonstrates use of default arguments.
Given the Image is Define the Working of Default Argument in C ++

Question 101

Question

MCQ▾

When are the global objects destroyed?

Choices

Choice (4)

a.

When the control comes out of the block in which they are being used.

b.

As soon as local objects die.

c.

When the program terminates.

d.

When the control comes out of the function in which they are being used.

Answer

c.

Explanation

  • Global variables exist for the whole program- when program terminates than global variables is destroyed.
  • Object outside all function bodies is known as global object.
  • Objects of classes outside any functions can be declared from anywhere in the program.
  • Such objects are globally available to all the function in the program.
  • Example:
  1. Classsample
  2. {
  3.     Intx;
  4.     Public:voidreadx() { cinx;}
  5. };
  6. Samples1; // global object
  7. Voidmain()
  8. {
  9.     Samples2; //local object
  10.     S1.readx();
  11. }

Developed by: