Welcome to the Classes and Operator Overloading in C++ MCQs Page
Dive deep into the fascinating world of Classes and Operator Overloading in C++ with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Classes and Operator Overloading in C++, a crucial aspect of Object Oriented Programming Using C++. In this section, you will encounter a diverse range of MCQs that cover various aspects of Classes and Operator Overloading in C++, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within Object Oriented Programming Using C++.
Check out the MCQs below to embark on an enriching journey through Classes and Operator Overloading in C++. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of Object Oriented Programming Using C++.
Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Classes and Operator Overloading in C++. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!
Classes and Operator Overloading in C++ MCQs | Page 33 of 39
Explore more Topics under Object Oriented Programming Using C++
class Bits
{
public:
static void MyFunction();
};
int main()
{
void(*ptr)() = &Bits::MyFunction;
return 0;
}
1. It can access only other static members of its class.
2. It can be called using the class name, instead of objects.
#include<iostream.h>
class Bits
{
public:
int x;
};
int main()
{
Bits *p = new Bits();
(*p).x = 10;
cout<< (*p).x << " " << p->x << " " ;
p->x = 20;
cout<< (*p).x << " " << p->x ;
return 0;
}
#include<iostream.h>
class Compscibits
{
static int x;
public:
static void SetData(int xx)
{
x = xx;
}
void Display()
{
cout<< x ;
}
};
int Compscibits::x = 0;
int main()
{
Compscibits::SetData(33);
Compscibits::Display();
return 0;
}#include<iostream.h>
class Compscibits
{
static int x;
public:
static void SetData(int xx)
{
x = xx;
}
static void Display()
{
cout<< x ;
}
};
int Compscibits::x = 0;
int main()
{
Compscibits::SetData(44);
Compscibits::Display();
return 0;
}#include<iostream.h>
class BitsTeam
{
int x, y;
public:
BitsTeam(int xx)
{
x = ++xx;
}
void Display()
{
cout<< --x << " ";
}
};
int main()
{
BitsTeam objBT(45);
objBT.Display();
int *p = (int*)&objBT;
*p = 23;
objBT.Display();
return 0;
}
#include<iostream.h>
class Compscibits
{
static int x;
public:
static void SetData(int xx)
{
this->x = xx;
}
static void Display()
{
cout<< x ;
}
};
int Compscibits::x = 0;
int main()
{
Compscibits::SetData(22);
Compscibits::Display();
return 0;
}#include<iostream.h>
class CompSci
{
public:
struct Bits
{
int x;
float y;
void Function(void)
{
y = x = (x = 4*4);
y = --y * y;
}
void Display()
{
cout<< y << endl;
}
}B;
}I;
int main()
{
I.B.Display();
return 0;
}
#include<iostream.h>
#include<string.h>
class Compscibits
{
int val;
public:
void SetValue(char *str1, char *str2)
{
val = strcspn(str1, str2);
}
void ShowValue()
{
cout<< val;
}
};
int main()
{
Compscibits objBits;
objBits.SetValue((char*)"CompSci", (char*)"Bits");
objBits.ShowValue();
return 0;
}
#include<iostream.h>
#include<string.h>
class Compscibits
{
public:
void GetData(char *s, int x, int y )
{
int i = 0;
for (i = x-1; y>0; i++)
{
cout<< s[i];
y--;
}
}
};
int main()
{
Compscibits objBits;
objBits.GetData((char*)"Welcome!", 1, 3);
return 0;
}
#include<iostream.h>
class BitsData
{
int x, y, z;
public:
BitsData(int xx, int yy, int zz)
{
x = ++xx;
y = ++yy;
z = ++zz;
}
void Show()
{
cout<< "" << x++ << " " << y++ << " " << z++;
}
};
int main()
{
BitsData objData(1, 2, 3);
objData.Show();
return 0;
}#include<iostream.h>
class Compscibits
{
int x;
float y;
public:
void Function()
{
x = 4;
y = 2.50; delete this;
}
void Display()
{
cout<< x << " " << y;
}
};
int main()
{
Compscibits *pBits = new Compscibits();
pBits->Function();
pBits->Function();
pBits->Display();
return 0;
}
#include<iostream.h>
class Compscibits
{
static int count;
public:
static void First(void)
{
count = 10;
}
static void Second(int x)
{
count = count + x;
}
static void Display(void)
{
cout<< count << endl;
}
};
int Compscibits::count = 0;
int main()
{
Compscibits :: First();
Compscibits :: Second(5);
Compscibits :: Display();
return 0;
}
Suggested Topics
Are you eager to expand your knowledge beyond Object Oriented Programming Using C++? We've curated a selection of related categories that you might find intriguing.
Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!