TCS Papers: Sample Questions 230 - 231 of 502

Examrace Placement Series prepares you for the toughest placement exams to top companies.

Question number: 230

» Languages » C & C Plus Plus

MCQ▾

Question

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

Choices

Choice (4) Response

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>int Square(int x){
  2.     return x*x;
  3.     }int Cube(int x){
  4.     return x*x*x;
  5.     }int main(){
  6.     int x =10;int choice;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.         case 0ptr = Squarebreak;case 1ptr = Cubebreak;
  12.     }
  13.     cout << "The result is: " << ptr(x) << endl;return 0;
  14. }
  • Output:

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

The result is: 100

Question number: 231

» Languages » C & C Plus Plus

Essay Question▾

Describe in Detail

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: COMPILERINCLUDE; S: SOURCEHEADERS; using the #include version of file inclusion, the compiler first checks the C: COMPILERINCLUDE directory for the specified file.

    • If the file is not found there, the compiler then checks the S: SOURCEHEADERS 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.