Languages-C & C Plus Plus [TCS Placement]: Sample Questions 20 - 21 of 119
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 20
Write in Short Short Answer▾
What are the different file extensions involved when programming in c?
EditExplanation
- Source code files in C are saved with . c file extension.
- Header files or library files have the . h file extension.
- Every time a program source code is successfully compiled, it creates an . obj object file, and an executable . exe file.
Question 21
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
#include <iostream>int Square(int x){
return x⚹x;
}int Cube(int x){
return x⚹x⚹x;
}int main(){
int x =10;int choice;do{
cout ≪ "Enter 0 for square value, 1 for cube value:";cin ≫ choice;
}
while (choice <0 || choice >1);int (⚹ptr) (int);
switch (choice){
case 0:ptr =Square; break;case 1:ptr =Cube; break;
}
cout ≪ "The result is:" ≪ ptr(x) ≪ endl;return 0;
}
- Output:
Enter 0 for square value, 1 for cube value: 0
The result is: 100