TCS Placement: Sample Questions 88 - 89 of 502

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 88

Question

MCQ▾

Which of the following concepts means determining at runtime what method to invoke?

Choices

Choice (4)

a.

Data hiding

b.

Dynamic typing

c.

Dynamic binding

d.

Dynamic loading

Answer

c.

Explanation

  • Dynamic binding means determining at runtime the method to invoke.
  • In OOPs Dynamic Binding refers to linking a procedure call to the code that will be executed- this is done at run time.
  • The code associated with the procedure in not known until the program is executed, which is also known as late binding.
  • Example
  1. #include<iostream>intSquare(intx){
  2.     returnxx;
  3.     }intCube(intx){
  4.     returnxxx;
  5.     }intmain(){
  6.     intx =10;intchoice;do{
  7.         cout ≪ "Enter 0 for square value, 1 for cube value:";cin ≫ choice;
  8.     }
  9.     while (choice <0 || choice >1);int (⚹ptr) (int);
  10.     switch (choice){
  11.         case0:ptr =Square; break;case1:ptr =Cube; break;
  12.     }
  13.     cout ≪ "The result is:" ≪ ptr(x) ≪ endl;return0;
  14. }
  • Output:

Enter 0 for square value, 1 for cube value: 0

The result is: 100

Question 89

Edit

Describe in Detail

Essay▾

What is the result of using option explicit?

Explanation

  • When writing C program, include files are used in two ways.
  • The first way is to surround the file with the angled brackets < and > .
    • This method of inclusion tells the preprocessor to look for the file in the predefined default location.
    • This predefined default location is often an INCLUDE environment variable that denotes the path to include files.
    • For instance, given the INCLUDE variable INCLUDE = C: ⧵COMPILER⧵INCLUDE; S: ⧵SOURCE⧵HEADERS; using the #include version of file inclusion, the compiler first checks the C: ⧵COMPILER⧵INCLUDE directory for the specified file.
    • If the file is not found there, the compiler then checks the S: ⧵SOURCE⧵HEADERS directory.
    • If the file is still not found, the preprocessor checks the current directory.
  • The second way to include files is to surround the file with double quotation marks.
    • This method of inclusion tells the preprocessor to look for the file in the current directory first, then look for it in the predefined locations. Using the #include file version of file inclusion and applying it to the preceding example, the preprocessor first checks the current directory for the specified file.
    • If the file is not found in the current directory, the C: COMPILERINCLUDE directory is searched.
    • If the file is still not found, the preprocessor checks the S: SOURCEHEADERS directory.
  • The #include method of file inclusion is often used to include standard headers such as stdio. h or stdlib. h.
  • The #include file include is used for nonstandard header files created for use in program.
  • If these headers are often modified in the current directory then programmer would want the preprocessor to use newly modified version of the header rather than the older, unmodified version.

Developed by: