My Report

C++ Basic Online Test – 3


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. What happens if we run the following code in both C and C++?

#include<stdio.h>
struct STRUCT
{
  int a;
  int func()
  {
      printf("HELLO THIS IS STRUCTURE\n");
  }
};
int main()
{
  struct STRUCT s;
  s.func();
  return 0;
}

2. What is the size of a character literal in C and C++?

3. Which of the following is accessed by a member function of a class?

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

#include<iostream>
using namespace std;
class A
{
  ~A(){
     cout<<"Destructor called\n";
   }
};
int main()
{
    A *a1 = new A();
    A *a2 = new A();
    return 0;
}

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

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

#include<iostream>
using namespace std;
int x = 1;
int main()
{
    int x = 2;
    {
        int x = 3;
        cout << ::x << endl;
    }
    return 0;
}

7. Which of the following is correct?

8. What happens if we run the following code in both C and C++?

#include<stdio.h>
struct STRUCT
{
  int a = 5;
  int func()
  {
      printf("%d\n", a);
  }
};
int main()
{
  struct STRUCT s;
  s.func();
  return 0;
}

9. What is the size of a character type in C and C++?

10. Which of the following operator has left to right associativity?

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

#include<iostream>
using namespace std;
int main ()
{
   int cin;
   cin >> cin;
   cout << "cin: " << cin;
   return 0;
}

12. Which of the following is correct?

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

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

14. Which of the following is the scope resolution operator?

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

#include<iostream>
using namespace std;
class A
{
  ~A(){
    cout<<"Destructor called\n";
  }
};
int main()
{
    A a;
    return 0;
}

 

Start practicing “1000 MCQs on C++”, and once you are ready, you can take tests on all topics by attempting our “C++ Test Series”.

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.