A Place for Latest Exam wise Questions, Videos, Previous Year Papers, Study Stuff for MCA Examinations - NIMCET
Previous Year Question (PYQs)
1
26.What is the output of the following program ? #include <iostream> using namespace std; template <class C1, class C2> bool is_equal (C1 var1, C2 var2) { return (var1 = = var2); } int main () { if (is_equal(10,10.0)) cout<< “Equal”; else cout<< “Not equal”; return 0; }
Solution
The function `is_equal` is a template that compares two variables of possibly different types.
In `main()`, we call `is_equal(10, 10.0)`.
- `10` is an integer (int).
- `10.0` is a double.
C++ allows implicit type conversion during comparison.
So, `10 == 10.0` evaluates to `true`.
Therefore, the condition in the `if` statement is true, and the output will be:
Equal
Online Test Series, Information About Examination, Syllabus, Notification and More.