1. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
typedef int num;
num a = 10, b = 15;
num c = a + b + a - b;
cout << c;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
typedef int num;
num a = 10, b = 15;
num c = a + b + a - b;
cout << c;
return 0;
}
2. Pick out the correct syntax of operator conversion.
3. What are the essential operators in c++?
4. What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class B
{
int b;
public:
B(int i){
b = i;
}
};
class C
{
B b;
public:
C(int i){
b = B(i);
}
friend void show();
};
void show()
{
C c(10);
cout<<"value of b is: "<<c.b.b<<endl;
}
int main(int argc, char const *argv[])
{
show();
return 0;
}
#include <iostream>
#include <string>
using namespace std;
class B
{
int b;
public:
B(int i){
b = i;
}
};
class C
{
B b;
public:
C(int i){
b = B(i);
}
friend void show();
};
void show()
{
C c(10);
cout<<"value of b is: "<<c.b.b<<endl;
}
int main(int argc, char const *argv[])
{
show();
return 0;
}
5. What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str ("nobody does like this");
string key ("nobody");
size_t f;
f = str.rfind(key);
if (f != string::npos)
str.replace (f, key.length(), "everybody");
cout << str << endl;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str ("nobody does like this");
string key ("nobody");
size_t f;
f = str.rfind(key);
if (f != string::npos)
str.replace (f, key.length(), "everybody");
cout << str << endl;
return 0;
}
6. What is the correct syntax of accessing a static member of a Class?
---------------------------
Example class:
class A
{
public:
static int value;
}
---------------------------
---------------------------
Example class:
class A
{
public:
static int value;
}
---------------------------
7. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class myclass
{
public:
int i;
myclass *operator->()
{return this;}
};
int main()
{
myclass ob;
ob->i = 10;
cout << ob.i << " " << ob->i;
return 0;
}
#include <iostream>
using namespace std;
class myclass
{
public:
int i;
myclass *operator->()
{return this;}
};
int main()
{
myclass ob;
ob->i = 10;
cout << ob.i << " " << ob->i;
return 0;
}
8. What is the syntax of user-defined data types?
9. Which is used to pass the large objects in c++?
10. How to stop your program from eating so much ram?
Read More Section(Classes and Objects in C plus plus)
Each Section contains maximum 100 MCQs question on Classes and Objects in C plus plus. To get more questions visit other sections.