My Report

C++ Programming Mock Test 4


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement
 10%

Question 1 of 10

1. Which keyword is used to declare the friend function?

Question 1 of 10

Question 2 of 10

2. What will be the output of the following C++ code?

 
    #include <iostream>
    #include <complex>
    using namespace std;
    int main()
    {
        complex<double> c_double(2, 3);
        complex<int> c_int(4, 5);
        c_double *= 2;
        c_double = c_int;
        cout << c_double;
        return 0;
    }

Question 2 of 10

Question 3 of 10

3. What will be the output of the following C++ code?

#include <iostream> 
#include <string>
using namespace std; 
int main(int argc, char const *argv[])
{
	char str[10];
	cin>>str;
	cout<<str;
	return 0;
}

Question 3 of 10

Question 4 of 10

4. What will be the output of the following C++ code?

#include <iostream>
#include <string>
using namespace std;
int main ()
{
  string str = "Sanfoundry!";
  cout<<str.capacity();
  cout<<str.size();
  return 0;
}

Question 4 of 10

Question 5 of 10

5. 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;
    }

Question 5 of 10

Question 6 of 10

6. Which container in c++ will take large objects?

Question 6 of 10

Question 7 of 10

7. What will be the output of the following C++ code?

 
    #include <iostream>
    using namespace std;
    int main ()
    {
        int a, b, c;
        a = 2;
        b = 7;
        c = (a > b) ? a : b;
        cout << c;
        return 0;
    }

Question 7 of 10

Question 8 of 10

8. Given the following C++ code. How would you define the < operator for Box class so that when boxes b1 and b2 are compared in if block the program gives correct result?

#include <iostream>
#include <string>
using namespace std;
class Box
{
	int capacity;
     public:
	Box(){}
	Box(double capacity){
		this->capacity = capacity;
	}
};

int main(int argc, char const *argv[])
{
	Box b1(10);
	Box b2 = Box(14);
	if(b1 < b2){
		cout<<"Box 2 has large capacity.";
	}
	else{
		cout<<"Box 1 has large capacity.";
	}
	return 0;
}

Question 8 of 10

Question 9 of 10

9. What is the size of the heap?

Question 9 of 10

Question 10 of 10

10. What is the syntax of overloading operator + for class A?

Question 10 of 10


 

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.