Question 1 of 25
Hints left: 3
Q1
What will be the output of the following C++ code? #include <iostream> using namespace std; int n(char, int); int (*p) (char, int) = n; int main() { (*p)('d', 9); p(10, 9); return 0; } int n(char c, int i) { cout << c << i; return 0; }
Q2
What is the ability to group some lines of code that can be included? in the program?
Q3
What will be the output of the following C++ code? #include <iostream> using namespace std; int add(int first, int second) { return first + second + 15; } int operation(int first, int second, int (*functocall)(int, int)) { return (*functocall)(first, second); } int main() { int a; int (*plus)(int, int) = add; a = operation(15, 10, plus); cout << a; return 0; }
Q4
What will be the output of the following C++ code? #include <iostream> using namespace std; void copy (int& a, int& b, int& c) { a *= 2; b *= 2; c *= 2; } int main () { int x = 1, y = 3, z = 7; copy (x, y, z); cout << "x =" << x << ", y =" << y << ", z =" << z; return 0; }
Q5
How many minimum number of functions should be present in a C++ program for its execution?
Q6
What is the default return type of a function?
Q7
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; string askNumber(string prompt = "Please enter a number: "); int main() { string number = askNumber(); cout << "Here is your number: " << number; return 0; } string askNumber(string prompt) { string number; cout << prompt; cin << number; return number; }
Q8
What will be the output of the following C++ code? #include <iostream> using namespace std; void square (int *x, int *y) { *x = (*x) * --(*y); } int main ( ) { int number = 30; square(&number, &number); cout << number; return 0; }
Q9
What will be the output of the following C++ code? #include<iostream> using namespace std; int fun(int x = 0, int y = 0, int z) { return (x + y + z); } int main() { cout << fun(10); return 0; }
Q10
What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int age = 0; try { if (age < 0) { throw "Positive Number Required"; } cout << age; } catch(const char *Message) { cout << "Error: " << Message; } return 0; }
Q11
Which of the following implements the module in the program?
Q12
Where does the execution of the program starts?
Q13
How many types of returning values are present in c++?
Q14
What changes you can do in the header files to avoid the redefinition that compiler will give when both the header files are included in the same program keeping the declaration of both the functions same? Content of h1.h ------------------------------------------------ h1.h #include <iostream> using namespace std; int func(int a){ cout<<"Multiplied by 2"; return 2*a; } ------------------------------------------------ Content of h2.h ------------------------------------------------ h2.h #include <iostream> using namespace std; int func(int a){ cout<<"divided by 2"; return a/2; } ------------------------------------------------
Q15
What will be the output of the following C++ code? #include <iostream> using namespace std; int main () { cout << "Value of __LINE__ : " << __LINE__ << endl; cout << "Value of __FILE__ : " << __FILE__ << endl; cout << "Value of __DATE__ : " << __DATE__ << endl; cout << "Value of __TIME__ : " << __TIME__ << endl; return 0; }
Q16
What will be the output of the following C++ code? #include <iostream> #include <stdarg.h> using namespace std; void fun(std::string msg, ...); int main() { fun("cPlusPlus", 1, 4, 7, 11, 0); return 0; } void fun(std::string msg, ...) { va_list ptr; int num; va_start(ptr, msg); num = va_arg(ptr, int); num = va_arg(ptr, int); cout << num; }
Q17
What will be the output of the following C++ code? #include <iostream> #include <stdarg.h> using namespace std; float avg( int Count, ... ) { va_list Numbers; va_start(Numbers, Count); int Sum = 0; for (int i = 0; i < Count; ++i ) Sum += va_arg(Numbers, int); va_end(Numbers); return (Sum/Count); } int main() { float Average = avg(10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9); cout << "Average of first 10 whole numbers : " << Average; return 0; }
Q18
What is the correct syntax of defining a namespace?
Q19
When we define the default values for a function?
Q20
Function overloading is also similar to which of the following?
Q21
What will be the output of the following C++ code? #include <iostream> using namespace std; double & WeeklyHours() { double h = 46.50; double &hours = h; return hours; } int main() { double hours = WeeklyHours(); cout << "Weekly Hours: " << hours; return 0; }
Q22
What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { char* buff; try { buff = new char[1024]; if (buff == 0) throw "Memory allocation failure!"; else cout << sizeof(buff) << "Byte successfully allocated!"<<endl; } catch(char *strg) { cout<<"Exception raised: "<<strg<<endl; } return 0; }
Q23
What will be the output of the following C++ code? #include <iostream> using namespace std; int gcd (int a, int b) { int temp; while (b != 0) { temp = a % b; a = b; b = temp; } return(a); } int main () { int x = 15, y = 25; cout << gcd(x, y); return(0); }
Q24
When will we use the function overloading?
Q25
What will be the output of the following C++ code? #include<iostream> using namespace std; class Test { protected: int x; public: Test (int i):x(i) { } void fun() const { cout << "fun() const " << endl; } void fun() { cout << "fun() " << endl; } }; int main() { Test t1 (10); const Test t2 (20); t1.fun(); t2.fun(); return 0; }