Question 1 of 25
Hints left: 3
Q1
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A { static int a; public: void change(int i){ a = i; } void value_of_a(){ cout<<a; } }; int main(int argc, char const *argv[]) { A a1 = A(); a1.change(5); a1.value_of_a(); return 0; }
Q2
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; int main(int argc, char const *argv[]) { string s1 = "Hello"; string s2 = "World"; string s3 = s1 + " " + s2; cout<<s3; return 0; }
Q3
When we are using heap operations what do we need to do to save the memory?
Q4
What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { double a = 21.09399; float b = 10.20; int c ; c = (int) a; cout << c ; c = (int) b; cout << c ; return 0; }
Q5
What is the header file for the string class?
Q6
Constructors are used to . . . . . . . .
Q7
How many types of representation are in the string?
Q8
Which method do we use to append more than one character at a time?
Q9
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class B { int b; public: B(){} B(int i){ b = i; } int show(){ return b; } }; class C { B b; public: C(int i){ b = B(i); } friend void show(){ C c(10); cout<<"value of b is: "<<c.b.show()<<endl; } }; int main(int argc, char const *argv[]) { C c(1); c.show(); return 0; }
Q10
Which is used to do the dereferencing?
Q11
Which header file is used to include the string object functions in C++?
Q12
Pick out the correct option.
Q13
Pick out the correct statement.
Q14
Pick out the correct statement.
Q15
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class Box{ int capacity; public: Box(){} Box(double capacity){ this->capacity = capacity; } bool operator<(Box b){ return b.capacity < this->capacity? true : false; } }; int main(int argc, char const *argv[]) { Box b1(10); Box b2 = Box(14); if(b1 < b2){ cout<<"B1's capacity is small"; } else{ cout<<"B2's capacity is small"; } return 0; }
Q16
What is the syntax of overloading operator + for class A?
Q17
What will be the output of the following C++ code? #include <iostream> #include <cstring> using namespace std; int main () { char str1[10] = "Hello"; char str2[10] = "World"; char str3[10]; int len ; strcpy( str3, str1); strcat( str1, str2); len = strlen(str1); cout << len << endl; return 0; }
Q18
Pick out the correct statement.
Q19
Which is the correct way of concatenating a character at the end of a string object? way 1: string s; s = s + 'a'; way 2: string s; s.push_back('a');
Q20
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class complex { int i; int j; public: complex(){} complex(int a, int b) { i = a; j = b; } complex operator+(complex c) { complex temp; temp.i = this->i + c.i; temp.j = this->j + c.j; return temp; } void operator+(complex c) { complex temp; temp.i = this->i + c.i; temp.j = this->j + c.j; temp.show_poss(); } void show(){ cout<<"Complex Number: "<<i<<" + i"<<j<<endl; } void show_poss(){ cout<<"Your result after addition will be: "<<i<<" + i"<<j<<endl; } }; int main(int argc, char const *argv[]) { complex c1(1,2); complex c2(3,4); c1 + c2; return 0; }
Q21
What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { double arr[] = {5.0, 6.0, 7.0, 8.0}; double *p = (arr+2); cout << *p << endl; cout << arr << endl; cout << *(arr+3) << endl; cout << *(arr) << endl; cout << *arr+9 << endl; return 0; }
Q22
What will be the output of the following C++ code if the string entered by the user is "Hello World"? #include <iostream> #include <string> using namespace std; int main(int argc, char const *argv[]) { string str; cin>>str; cout<<str; return 0; }
Q23
Which header file is used to declare the complex number?
Q24
Pick the other name of operator function.
Q25
What is the identifier given to string class to declare string objects?