My Report

C++ Programming Practice Test 1


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

1. Implementation dependent aspects about an implementation can be found in ____

2. Which operator is overloaded for a cout object?

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

#include <iostream>
using namespace std;
class Test
{
    static int x;
  public:
    Test() { x++; }
    static int getX() {return x;}
};
int Test::x = 0;
int main()
{
    cout << Test::getX() << " ";
    Test t[5];
    cout << Test::getX();
}

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

    #include <iostream>
    using namespace std;
    int main()
    {
        float i = 123.0f;
        cout << i << endl;
        return 0;
    } 

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

#include<iostream>
using namespace std;
int x[100];
int main()
{
    cout << x[99] << endl;
}

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

    #include <iostream>
    using namespace std;
    int main()
    {
    	int x = -1;
        unsigned int y = 2;

        if(x > y) 
        {
        	cout << "x is greater";
    	}
        else 
        {
    		cout << "y is greater";
    	}      
    }

7. Which function is used to write a single character to console in C++?

8. Which of the following is called address operator?

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

#include <iostream>
using namespace std;
class A{
public:
	A(){
		cout<<"Constructor called\n";
	   }
	~A(){
		cout<<"Destructor called\n";
	    }
};
int main(int argc, char const *argv[])
{
	A *a = new A[5];
	delete a;
	return 0;
}

10. What happens if the following program is compiled in both C and C++?

#include<stdio.h>
struct STRUCT
{
  int static a;
};
int main()
{
  struct STRUCT s;
  return 0;
}

 

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.