Question 1 of 25
Hints left: 3
Q1
What will be the output of the following C++ code? #include <iostream> using namespace std; namespace space { int x = 10; } namespace space { int y = 15; } int main(int argc, char * argv[]) { space::x = space::y =5; cout << space::x << space::y; }
Q2
What does the client module import?
Q3
How do you access the third element of an array named 'arr' in C++?
Q4
Which of the following is important in a function?
Q5
Which symbol is used to declare the preprocessor directives?
Q6
What will be the output of the following C++ code? #include <iostream> using namespace std; void func(int x) { cout << x ; } int main() { void (*n)(int); n = &func; (*n)( 2 ); n( 2 ); return 0; }
Q7
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; namespace A{ int var = 10; } namespace B{ int var = 5; } int main() { int var = 20; using namespace B; cout<<var; }
Q8
What is the size of the following array declaration in C++: char str[10];?
Q9
What will be the output of the following C++ code? #include <iostream> using namespace std; namespace Box1 { int a = 4; } namespace Box2 { int a = 13; } int main () { int a = 16; Box1::a; Box2::a; cout << a; return 0; }
Q10
What will be the output of the following C++ code? #include <iostream> using namespace std; double division(int a, int b) { if (b == 0) { throw "Division by zero condition!"; } return (a / b); } int main () { int x = 50; int y = 2; double z = 0; try { z = division(x, y); cout << z; } catch(const char *msg) { cerr << msg; } return 0; }
Q11
What will be the output of the following C++ code? #include <iostream> using namespace std; namespace first { int x = 5; int y = 10; } namespace second { double x = 3.1416; double y = 2.7183; } int main () { using first::x; using second::y; bool a, b; a = x > y; b = first::y < second::x; cout << a << b; return 0; }
Q12
What is the purpose of the 'strlen()' function in C++?
Q13
What will be the output of following C++ code? #include <iostream> #include <string> using namespace std; namespace My_old_school_and_college_friends_number { long int f1 = 9999999999; long int f2 = 1111111111; } namespace contacts = My_old_school_and_college_friends_number; int main(){ cout<<contacts::f1; }
Q14
What will be the output of the following C++ code? Content of header file h1.h ------------------------------------------------ h1.h #include <iostream> using namespace std; namespace A{ int func(int a){ cout<<"using namespace A"; return 2*a; } } ------------------------------------------------ Content of header file h2.h ------------------------------------------------ h2.h #include <iostream> using namespace std; namespace B{ float func(float a){ cout<<"using namespace B"; return 2*a; } } ------------------------------------------------ Content of program.cpp ------------------------------------------------ #include <iostream> #include <string> #include "h1.h" #include "h2.h" using namespace std; using namespace A; using namespace B; int main(int argc, char const *argv[]) { /* code */ int a = 10; float b = 10.0; cout<<A::func(a)<<endl; cout<<A::func(b); return 0; } ------------------------------------------------
Q15
What will be the output of the following C++ code? Content of header file h1.h ------------------------------------------------ h1.h #include <iostream> using namespace std; namespace A{ int func(int a){ cout<<"using namespace A"; return 2*a; } } ------------------------------------------------ Content of header file h2.h ------------------------------------------------ h2.h #include <iostream> using namespace std; namespace B{ float func(float a){ cout<<"using namespace B"; return 2*a; } } ------------------------------------------------ Content of program.cpp ------------------------------------------------ #include <iostream> #include <string> #include "h1.h" #include "h2.h" using namespace std; using namespace A; using namespace B; int main(int argc, char const *argv[]) { /* code */ int a = 10; float b = 10.0; cout<<func(a)<<endl; cout<<func(b); return 0; } -----------------------------------------------
Q16
What is the mandatory preprocessor directive for c++?
Q17
If the user did not supply the value, what value will it take?
Q18
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; namespace A{ int var = 10; } namespace B{ int var = 5; } int main() { using namespace B; cout<<var; }
Q19
How do you initialize all elements of an integer array named 'arr' to zero in C++?
Q20
What will be the output of the following C++ code? #include <iostream> using namespace std; #define MIN(a,b) (((a)<(b)) ? a : b) int main () { float i, j; i = 100.1; j = 100.01; cout <<"The minimum is " << MIN(i, j) << endl; return 0; }
Q21
What will be the output of the following C++ code? #include <iostream> using namespace std; void func(int a, bool flag = true) { if (flag == true ) { cout << "Flag is true. a = " << a; } else { cout << "Flag is false. a = " << a; } } int main() { func(200, false); return 0; }
Q22
Which of the header file should be added in the following C++ code to properly run the program? #include <iostream> using namespace std; int print_all (int num, ...) { int sum = 0; va_list args; va_start (args,num); for (int i = 0; i < num; i++) { int num = va_arg (args,int); cout<<num<<" "; } va_end (args); return sum; } int main (void) { print_all(8, 1, 2, -1, 4, 12, -2, 9, 7); return 0; }
Q23
What will be the output of the following C++ code? #include <iostream> #include <exception> using namespace std; int main() { try { int * array1 = new int[100000000]; int * array2 = new int[100000000]; int * array3 = new int[100000000]; int * array4 = new int[100000000]; cout << "Allocated successfully"; } catch(bad_alloc&) { cout << "Error allocating the requested memory." << endl; } return 0; }
Q24
What will be the output of the following C++ code? #include <iostream> using namespace std; void mani() void mani() { cout<<"hai"; } int main() { mani(); return 0; }
Q25
What is the correct way to declare a one-dimensional array in C++?