C++ LEVEL TEST
About C++ Test
  • There are 10 questions in this C++ test.
  • They cover all levels from basic to advanced in a random order.
  • Some of the questions are easier, some are more difficult. Don’t worry if you don’t know the answer!
  • Don’t use any books or websites to help you – the idea is to find your natural level!

What's the size of an empty class?




Which of the following correctly declares an array in C++?




Which of the following symbol is used to declare the preprocessor directives in C++?




Which concept allows you to reuse the written code in C++?




How structures and classes in C++ differ?




What is the output of the following program?

#include <iostream>

using namespace std;
void swap(int m, int n) {
   int x = m;

	m = n;
	n = x;
}
main() {
   int x = 5, y = 3;
   
	swap(x,y);
	cout <<x <<" " <<y;
}



What is the output of the following program?

#include <iostream>
using namespace std;
 

int main()
{
    double d = 1.2345678;
 
    // Set precision to 5
    cout.precision(5);
 
    // Print d
    cout << d << endl;
 
    // Set precision to 7
    cout.precision(7);
 
    // Print d
    cout << d << endl;
 
    return 0;
}



What is the output of the following program?

#include <iostream>   
#include <iomanip>
 
using namespace std;
int main()
{
int val = 50;
 
cout << "Hex Value:" << " " << hex << val << endl;
cout << "Octal Value:" << " " << oct << val << endl;
cout << "Setbase Value:" << " " << setbase(8) << val << endl;
cout << "Setbase Value:" << " " << setbase(16) << val << endl;

return 0;
}



What is the output of the following program?

#include <iostream>
#include <algorithm> int main() { int arr[] = { 1, 2, 3, 4, 5 }; int mul = 5; std::for_each(arr, arr + sizeof(arr) / sizeof(int), [](int x) { x = x*mul; }); std::for_each(arr, arr + sizeof(arr) / sizeof(int), [](int x) { std::cout <<x<<" "; }); std::cout << std::endl; }



What is the output of the following program?

#include <iostream> 
  
using namespace std;    
  
class Dummy 
{ 
  static char c1; 
  char c2; 
}; 
  
char Dummy::c1; 
  
int main() 
{ 
    cout <<"sizeof(Dummy): " <<sizeof(Dummy); 
    return 0; 
}